# # patch "ChangeLog" # from [5e4e187101bf5df8e847e24ef7f5887ed4fcafdc] # to [6886692129aed899cd387044fc87e7c6cbe2ca56] # # patch "constants.cc" # from [8170662bde7da5a7e3600e2a55b6dfd05658463c] # to [c153a952d2426d8faa02b2953bc632852405d93e] # # patch "constants.hh" # from [9d0ee60b98490a03c437d218ef8b03cd46204970] # to [9397b4c694811c99edf4579c0738effe49719666] # # patch "packet.cc" # from [f3dd7284eba0d23f4fb5d549ebabec0fd8055a1a] # to [00bd3aba6a226fbf464b1dcb503ddb585697f0de] # # patch "tests/t_genkey.at" # from [79ddbe2d6c180820c0ced9ca871a56d5ff194501] # to [d130247d78765f58a06db900908980724a853615] # ======================================================================== --- ChangeLog 5e4e187101bf5df8e847e24ef7f5887ed4fcafdc +++ ChangeLog 6886692129aed899cd387044fc87e7c6cbe2ca56 @@ -1,3 +1,14 @@ +2005-12-02 Matthew Gregan + + * packet.cc (feed_packet_consumer::feed_packet_consumer, + extract_packets): Move duplicated sets of regexs for key IDs, + certs, etc. into constants.cc. + * constants.{cc,hh}: Add regex strings extracted from packet.cc. Also + fix the key ID regex to accept a few characters we allowed in + legal_key_name_bytes already. + * tests/t_genkey.at: Test good and bad keys with all characters we + allow in the user portion of a key id. + 2005-12-01 Matthew Gregan * database.cc: Revert last change; db version and db migrate need ======================================================================== --- constants.cc 8170662bde7da5a7e3600e2a55b6dfd05658463c +++ constants.cc c153a952d2426d8faa02b2953bc632852405d93e @@ -56,11 +56,15 @@ " \r\n\t" ; + std::string const regex_legal_packet_bytes("([a-zA-Z0-9+/=[:space:]]+)"); + // all the ASCII characters (bytes) which are legal in a SHA1 hex id char const * const legal_id_bytes = "0123456789abcdef" ; + std::string const regex_legal_id_bytes("([[:xdigit:]]{40})"); + // all the ASCII characters (bytes) which are legal in an ACE string char const * const legal_ace_bytes = // LDH characters @@ -80,7 +84,9 @@ "0123456789" "-" ; - + + std::string const regex_legal_cert_name_bytes("([-a-zA-Z0-9]+)"); + // all the ASCII characters (bytes) which can occur in key names char const * const legal_key_name_bytes = // LDH characters @@ -94,7 +100,9 @@ // label and component separators ".@" ; - + + std::string const regex_legal_key_name_bytes("(address@hidden)"); + // all the ASCII characters (bytes) which are illegal in a (file|local)_path char const illegal_path_bytes_arr[33] = ======================================================================== --- constants.hh 9d0ee60b98490a03c437d218ef8b03cd46204970 +++ constants.hh 9397b4c694811c99edf4579c0738effe49719666 @@ -58,18 +58,30 @@ // all the ASCII characters (bytes) which are legal in a packet extern char const * const legal_packet_bytes; + // boost regex that matches the bytes in legal_packet_bytes + extern std::string const regex_legal_packet_bytes; + // all the ASCII characters (bytes) which are legal in an ACE string extern char const * const legal_ace_bytes; // all the ASCII characters (bytes) which are legal in a SHA1 hex id extern char const * const legal_id_bytes; + // boost regex that matches the bytes in legal_id_bytes + extern std::string const regex_legal_id_bytes; + // all the ASCII characters (bytes) which can occur in cert names extern char const * const legal_cert_name_bytes; + // boost regex that matches the bytes in legal_cert_name_bytes + extern std::string const regex_legal_cert_name_bytes; + // all the ASCII characters (bytes) which can occur in key names extern char const * const legal_key_name_bytes; + // boost regex that matches the bytes in legal_key_name_bytes + extern std::string const regex_legal_key_name_bytes; + // all the ASCII characters (bytes) which are illegal in a (file|local)_path extern char const * const illegal_path_bytes; ======================================================================== --- packet.cc f3dd7284eba0d23f4fb5d549ebabec0fd8055a1a +++ packet.cc 00bd3aba6a226fbf464b1dcb503ddb585697f0de @@ -13,6 +13,7 @@ #include "app_state.hh" #include "change_set.hh" +#include "constants.hh" #include "packet.hh" #include "revision.hh" #include "sanity.hh" @@ -1349,10 +1350,10 @@ std::string sp; feed_packet_consumer(size_t & count, packet_consumer & c) : count(count), cons(c), - ident("([[:xdigit:]]{40})"), - key("(address@hidden)"), - certname("([-a-zA-Z0-9]+)"), - base("([a-zA-Z0-9+/=[:space:]]+)"), + ident(constants::regex_legal_id_bytes), + key(constants::regex_legal_key_name_bytes), + certname(constants::regex_legal_cert_name_bytes), + base(constants::regex_legal_packet_bytes), sp("[[:space:]]+") {} void require(bool x) const @@ -1480,11 +1481,10 @@ // pubkey packet immediately followed by a matching privkey // packet into a keypair packet (which is what privkey packets // have been replaced by) - string const key("(address@hidden)"); - string const base64("([a-zA-Z0-9+/=[:space:]]+)"); - string const pubkey("\\[pubkey[[:space:]]+"+ key + "\\]" + base64 - + "\\[end\\]"); - string const privkey("\\[privkey \\1\\]" + base64 + "\\[end\\]"); + string const pubkey("\\[pubkey[[:space:]]+" + constants::regex_legal_key_name_bytes + + "\\]" + constants::regex_legal_packet_bytes + "\\[end\\]"); + string const privkey("\\[privkey \\1\\]" + constants::regex_legal_packet_bytes + + "\\[end\\]"); string const pubkey_privkey = pubkey + "[[:space:]]*" + privkey; string const keypair_fmt("[keypair $1]$2#$3[end]"); r = regex_replace(s, regex(pubkey_privkey), keypair_fmt); ======================================================================== --- tests/t_genkey.at 79ddbe2d6c180820c0ced9ca871a56d5ff194501 +++ tests/t_genkey.at d130247d78765f58a06db900908980724a853615 @@ -62,4 +62,20 @@ address@hidden AT_CHECK((echo $BADKEY2; echo $BADKEY2) | MONOTONE genkey $BADKEY2, [1], [ignore], [ignore]) +# fourth section, keys with all supported characters (for the user portion) +# in the user portion work, keys with the same in the domain portion don't +# work. address@hidden + +AT_CHECK((echo $GOODKEY; echo $GOODKEY) | MONOTONE genkey $GOODKEY, [], [ignore], [ignore]) +#exists +AT_CHECK(MONOTONE ls keys, [], [stdout]) +AT_CHECK(grep $GOODKEY stdout, [], [ignore]) + +# bad keys fail address@hidden +AT_CHECK((echo $BADKEY1; echo $BADKEY1) | MONOTONE genkey $BADKEY1, [1], [ignore], [ignore]) address@hidden +AT_CHECK((echo $BADKEY2; echo $BADKEY2) | MONOTONE genkey $BADKEY2, [1], [ignore], [ignore]) + AT_CLEANUP