Binary files JohnTheRipper.orig/.git/index and JohnTheRipper/.git/index differ 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-15 01:52:57.622687618 +0000 +++ JohnTheRipper/src/gpg2john.cpp 2013-03-16 22:17:21.274047830 +0000 @@ -1,6 +1,9 @@ /* * pgpry - PGP private key recovery * Copyright (C) 2010 Jonas Gehring + * Modified for John the Ripper: + * Copyright (C) 2012 Dhiru Kholia + * Copyright (C) 2013 Lukas Odzioba * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,10 +22,28 @@ #include #include #include +#include +#include +#include #include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include + #include "gpg2john.h" +using namespace std; + + namespace CryptUtils { @@ -89,9 +110,6 @@ uint32_t digestSize(HashAlgorithm algori } // namespace CryptUtils -#include -#include - class Memblock { public: @@ -202,15 +220,12 @@ inline Memblock &Memblock::operator+=(co // Convenience functions -inline std::ostream& operator<<(std::ostream &out, const Memblock &in) +inline ostream& operator<<(ostream &out, const Memblock &in) { out << in.data; return out; } -#include -#include - // Constructor Key::Key() @@ -263,7 +278,12 @@ const String2Key &Key::string2Key() cons void readPacketHeader(PIStream &in, PacketHeader &header){ - in >> header; + try { + in >> header; + } catch (...) { + cerr<<"packet header exception"< + // Constructor -PIStream::PIStream(std::istream &stream) +PIStream::PIStream(istream &stream) : m_in(stream), m_read(0), m_armored(false), m_b64count(0), m_b64buf(0) { @@ -623,13 +643,7 @@ void PIStream::dearmor() } while (m_in.good() && buffer[0] != 0); } -#include -#include -#include -#include -#include -#include #define KEYBUFFER_LENGTH 8192 @@ -763,27 +777,19 @@ String2Key &String2Key::operator=(const return *this; } -#include -#include -#include -#include -#include -#include -#include - namespace Utils { // Wrapper for strtol() template -static bool tstr2int(const std::string &str, T *i) +static bool tstr2int(const string &str, T *i) { char *end; long val = strtol(str.c_str(), &end, 0); if (errno == ERANGE || str.c_str() == end - || val > std::numeric_limits::max() - || val < std::numeric_limits::min()) { + || val > numeric_limits::max() + || val < numeric_limits::min()) { return false; } @@ -792,27 +798,27 @@ static bool tstr2int(const std::string & } // Wrapper for strtol() -bool str2int(const std::string &str, int32_t *i) +bool str2int(const string &str, int32_t *i) { return tstr2int(str, i); } // Wrapper for strtol() -bool str2int(const std::string &str, uint32_t *i) +bool str2int(const string &str, uint32_t *i) { return tstr2int(str, i); } // Converts an interger to a string -std::string int2str(int32_t i) +string int2str(int32_t i) { - std::stringstream out; + stringstream out; out << i; return out.str(); } // Removes white-space characters at the beginning and end of a string -void trim(std::string *str) +void trim(string *str) { int32_t start = 0; int32_t end = str->length()-1; @@ -830,17 +836,17 @@ void trim(std::string *str) } // Removes white-space characters at the beginning and end of a string -std::string trim(const std::string &str) +string trim(const string &str) { - std::string copy(str); + string copy(str); trim(©); return copy; } // Split a string using the given token -std::vector split(const std::string &str, const std::string &token) +vector split(const string &str, const string &token) { - std::vector parts; + vector parts; size_t index = 0; if (token.length() == 0) { @@ -853,7 +859,7 @@ std::vector split(const std while (index < str.length()) { size_t pos = str.find(token, index); parts.push_back(str.substr(index, pos - index)); - if (pos == std::string::npos) { + if (pos == string::npos) { break; } index = pos + token.length(); @@ -865,13 +871,13 @@ std::vector split(const std return parts; } -// sprintf for std::string -std::string strprintf(const char *format, ...) +// sprintf for string +string strprintf(const char *format, ...) { va_list vl; va_start(vl, format); - std::ostringstream os; + ostringstream os; const char *ptr = format-1; while (*(++ptr) != '\0') { @@ -912,7 +918,7 @@ std::string strprintf(const char *format default: #ifndef NDEBUG - std::cerr << "Error in strprintf(): unknown format specifier " << *ptr << std::endl; + cerr << "Error in strprintf(): unknown format specifier " << *ptr << endl; exit(1); #endif break; @@ -924,9 +930,9 @@ std::string strprintf(const char *format } // Returns an option from the given map or a default value -std::string defaultOption(const std::map &options, const std::string name, const std::string &def) +string defaultOption(const map &options, const string name, const string &def) { - std::map::const_iterator it = options.find(name); + map::const_iterator it = options.find(name); if (it != options.end()) { return (*it).second; } else { @@ -935,7 +941,7 @@ std::string defaultOption(const std::map } // Returns an option from the given map or a default value -int32_t defaultOption(const std::map &options, const std::string name, int32_t def) +int32_t defaultOption(const map &options, const string name, int32_t def) { int32_t i = 0; if (str2int(defaultOption(options, name, int2str(def)), &i)) { @@ -947,11 +953,6 @@ int32_t defaultOption(const std::map -#include -#include - -using namespace std; #define N 128 @@ -970,9 +971,28 @@ enum { +char *strip_basename(char* filename) +{ + int len; + char *base = basename(strdup(filename)); + + if (!base || !*base) + strcpy(base, filename); + len = strlen(base); + if (len > 4) { + len -= 4; + if (!strcmp(&base[len], ".gpg") || !strcmp(&base[len],".asc") || !strcmp(&base[len], ".pgp")) { + base[len] = 0; + } + } + return base; +} + void key2john(Key &key,char *filename) { const String2Key &s2k = key.string2Key(); - printf("%s:$gpg$*%d*%d*%d*", filename, key.m_algorithm, key.m_datalen, key.bits()); + char *base=strip_basename(filename); + printf("%s:$gpg$*%d*%d*%d*", base, key.m_algorithm, key.m_datalen, key.bits()); + free(base); 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); @@ -996,11 +1016,12 @@ int process_file(char *filename) { ifstream inStream; inStream.open(filename); if(!inStream.is_open()) { - std::cerr << "Couldn't open file "<