Binary files JohnTheRipper.orig/run/gpg2john and JohnTheRipper/run/gpg2john differ diff -urpN JohnTheRipper.orig/src/gpg2john.cpp JohnTheRipper/src/gpg2john.cpp --- JohnTheRipper.orig/src/gpg2john.cpp 2013-03-12 02:50:42.461972824 +0000 +++ JohnTheRipper/src/gpg2john.cpp 2013-03-12 02:44:43.000000000 +0000 @@ -261,12 +261,21 @@ const String2Key &Key::string2Key() cons return m_s2k; } -// Reads a key data from a stream -PIStream &Key::operator<<(PIStream &in) -{ - // Read packet header - PacketHeader header; + +void readPacketHeader(PIStream &in, PacketHeader &header){ in >> header; +} + +void suckUnwantedPacket(PIStream &in, PacketHeader &header){ + uint8_t tmp; + for(int i=0;i>tmp; + } + tmp=0; +} + +void readSecretKey(PIStream &in,PacketHeader &header,Key &key) +{ if (!header.valid()) { throw "Invalid packet header"; } @@ -276,56 +285,55 @@ PIStream &Key::operator<<(PIStream &in) uint32_t headerOff = in.pos(); // Read public key - in >> m_version; - if (m_version != 3 && m_version != 4) { - throw Utils::strprintf("Unsupported key version %d", m_version); - } - in >> m_time; - if (m_version == 3) { - in >> m_expire; + in >> key.m_version; + if (key.m_version != 3 && key.m_version != 4) { + throw Utils::strprintf("Unsupported key version %d", key.m_version); + } + in >> key.m_time; + if (key.m_version == 3) { + in >> key.m_expire; } uint8_t tmp; - in >> tmp; m_algorithm = (CryptUtils::PublicKeyAlgorithm)tmp; - if (m_algorithm == CryptUtils::PKA_RSA_ENCSIGN) { - m_rsa = RSA_new(); - in >> m_rsa->n; - in >> m_rsa->e; - } else if (m_algorithm == CryptUtils::PKA_DSA) { - m_dsa = DSA_new(); - in >> m_dsa->p; - in >> m_dsa->q; - in >> m_dsa->g; - in >> m_dsa->pub_key; + in >> tmp; key.m_algorithm = (CryptUtils::PublicKeyAlgorithm)tmp; + if (key.m_algorithm == CryptUtils::PKA_RSA_ENCSIGN) { + key.m_rsa = RSA_new(); + in >> key.m_rsa->n; + in >> key.m_rsa->e; + } else if (key.m_algorithm == CryptUtils::PKA_DSA) { + key.m_dsa = DSA_new(); + in >> key.m_dsa->p; + in >> key.m_dsa->q; + in >> key.m_dsa->g; + in >> key.m_dsa->pub_key; } else { - throw Utils::strprintf("Unsupported public-key algorithm %d", m_algorithm); + throw Utils::strprintf("Unsupported public-key algorithm %d", key.m_algorithm); } // Read private key - in >> m_s2k; - if (m_s2k.usage() != 0) { + in >> key.m_s2k; + if (key.m_s2k.usage() != 0) { // Encrypted - m_datalen = header.length() - in.pos() + headerOff; - m_data = new uint8_t[m_datalen]; - if (in.read((char *)m_data, m_datalen) != m_datalen) { + key.m_datalen = header.length() - in.pos() + headerOff; + key.m_data = new uint8_t[key.m_datalen]; + if (in.read((char *)key.m_data, key.m_datalen) != key.m_datalen) { throw "Premature end of data stream"; } } else { // Plaintext - if (m_algorithm == CryptUtils::PKA_RSA_ENCSIGN) { - in >> m_rsa->d; - in >> m_rsa->p; - in >> m_rsa->q; - in >> m_rsa->iqmp; - } else if (m_algorithm == CryptUtils::PKA_DSA) { - in >> m_dsa->priv_key; + if (key.m_algorithm == CryptUtils::PKA_RSA_ENCSIGN) { + in >> key.m_rsa->d; + in >> key.m_rsa->p; + in >> key.m_rsa->q; + in >> key.m_rsa->iqmp; + } else if (key.m_algorithm == CryptUtils::PKA_DSA) { + in >> key.m_dsa->priv_key; } } - m_locked = (m_s2k.usage() != 0); - - return in; + key.m_locked = (key.m_s2k.usage() != 0); } + // Assignment operator Key &Key::operator=(const Key &other) { @@ -960,38 +968,11 @@ enum { SPEC_ITERATED_SALTED = 3 }; -int main(int argc, char **argv) -{ - if(argc < 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(-1); - } - ifstream inStream; - inStream.open(argv[1]); - Key key; - try { - PIStream in(inStream); - in >> key; - } catch(const std::string & str) { - std::cerr << "Exception while parsing key: " << str << std:: - endl; - return EXIT_FAILURE; - } - catch(const char *cstr) { - std::cerr << "Exception while parsing key: " << cstr << std:: - endl; - return EXIT_FAILURE; - } - if (!key.locked()) { - std:: - cerr << "Err, this secret key doesn't seem to be encrypted" - << std::endl; - return EXIT_FAILURE; - } +void key2john(Key &key,char *filename) { const String2Key &s2k = key.string2Key(); - printf("%s:$gpg$*%d*%d*%d*", argv[1], key.m_algorithm, key.m_datalen, key.bits()); + printf("%s:$gpg$*%d*%d*%d*", filename, key.m_algorithm, key.m_datalen, key.bits()); print_hex(key.m_data, key.m_datalen); printf("*%d*%d*%d*%d*%d*", s2k.m_spec, s2k.m_usage, s2k.m_hashAlgorithm, s2k.m_cipherAlgorithm, s2k.bs); print_hex(s2k.m_iv, s2k.bs); @@ -1008,5 +989,66 @@ int main(int argc, char **argv) break; } printf("\n"); - exit(1); +} + + +int process_file(char *filename) { + ifstream inStream; + inStream.open(filename); + if(!inStream.is_open()) { + std::cerr << "Couldn't open file "<\n", argv[0]); + return EXIT_FAILURE; + } + int ret=EXIT_SUCCESS; + for (int i = 1; i < argc; i++) { + if (process_file(argv[i])!=EXIT_SUCCESS) { + ret=EXIT_FAILURE; + } + } + return ret; } diff -urpN JohnTheRipper.orig/src/gpg2john.h JohnTheRipper/src/gpg2john.h --- JohnTheRipper.orig/src/gpg2john.h 2013-03-12 02:50:42.461972824 +0000 +++ JohnTheRipper/src/gpg2john.h 2013-03-10 22:50:34.000000000 +0000 @@ -157,7 +157,6 @@ class Key const String2Key &string2Key() const; PIStream &operator<<(PIStream &in); - POStream &operator>>(POStream &out); Key &operator=(const Key &other); @@ -193,11 +192,6 @@ inline PIStream &operator>>(PIStream &in return (key << in); } -inline POStream &operator<<(POStream &out, Key &key) -{ - return (key >> out); -} - #endif // KEY_H_ @@ -205,8 +199,6 @@ inline POStream &operator<<(POStream &ou #define PACKETHEADER_H_ class PIStream; -class POStream; - class PacketHeader { @@ -232,7 +224,6 @@ class PacketHeader int32_t length() const; PIStream &operator<<(PIStream &in); - POStream &operator>>(POStream &out); private: Format m_format; @@ -247,12 +238,6 @@ inline PIStream &operator>>(PIStream &in return (header << in); } -inline POStream &operator<<(POStream &out, PacketHeader &header) -{ - return (header >> out); -} - - #endif // PACKETHEADER_H_ #ifndef PISTREAM_H_ diff -urpN JohnTheRipper.orig/src/Makefile JohnTheRipper/src/Makefile --- JohnTheRipper.orig/src/Makefile 2013-03-12 02:50:42.469972824 +0000 +++ JohnTheRipper/src/Makefile 2013-03-12 02:51:25.197972486 +0000 @@ -230,7 +230,7 @@ PROJ = ../run/john ../run/unshadow ../ru ../run/tgtsnarf ../run/racf2john ../run/mozilla2john ../run/hccap2john \ ../run/pwsafe2john ../run/raw2dyna ../run/keepass2john ../run/pfx2john \ ../run/keychain2john ../run/keyring2john ../run/kwallet2john \ - ../run/dmg2john ../run/putty2john john.local.conf + ../run/dmg2john ../run/putty2john gpg2john john.local.conf PROJ_DOS = ../run/john.bin ../run/john.com \ ../run/unshadow.com ../run/unafs.com ../run/unique.com \ ../run/undrop.com \