| | 193 | io.puts "Version - #{version}" |
|---|
| | 194 | case version |
|---|
| | 195 | when 2, 3 |
|---|
| | 196 | scanner_v3(io, port, length - 1) |
|---|
| | 197 | when 4 |
|---|
| | 198 | scanner_v4(io, port, length - 1) |
|---|
| | 199 | else |
|---|
| | 200 | raise "Unknown version: #{version}" |
|---|
| | 201 | end |
|---|
| | 202 | end |
|---|
| | 203 | |
|---|
| | 204 | def self.scanner_v3(io, port, length) |
|---|
| | 205 | require 'pgp/packet/signaturev3' |
|---|
| | 206 | initpos = port.readlength |
|---|
| | 207 | header_length = load_1octet(port) |
|---|
| | 208 | raise "Must be 5" if header_length != 5 |
|---|
| | 209 | signature_type = load_signature_type(port) |
|---|
| | 210 | creation_time = load_time(port) |
|---|
| | 211 | keyid = port.read(8) |
|---|
| | 212 | pkey_algorithm = load_pkey_algorithm(port) |
|---|
| | 213 | hash_algorithm = load_hash_algorithm(port) |
|---|
| | 214 | qt = load_hash_quicktest(port) |
|---|
| | 215 | packet = SignatureV3.new(signature_type, pkey_algorithm, hash_algorithm) |
|---|
| | 216 | packet.creation_time = creation_time |
|---|
| | 217 | packet.keyid = keyid |
|---|
| | 218 | packet.scan(io) |
|---|
| | 219 | io.puts "Hash left 2 bytes - " + qt.unpack("H*")[0] |
|---|
| | 220 | io.puts "Signature: #{PKeyAlgorithm.label(pkey_algorithm)}" |
|---|
| | 221 | io.indent(4) do |
|---|
| | 222 | sig = load_signature(port, |
|---|
| | 223 | length - (port.readlength - initpos), pkey_algorithm) |
|---|
| | 224 | io.puts PKeyAlgorithm.dump_signature(pkey_algorithm, sig) |
|---|
| | 225 | end |
|---|
| | 226 | end |
|---|
| | 227 | |
|---|
| | 228 | def self.scanner_v4(io, port, length) |
|---|
| | 229 | initpos = port.readlength |
|---|
| 266 | | |
|---|
| 267 | | |
|---|
| 268 | | if __FILE__ == $0 |
|---|
| 269 | | include PGP |
|---|
| 270 | | require 'pgp/hexdump' |
|---|
| 271 | | require 'pgp/mpi' |
|---|
| 272 | | require 'pgp/packet/publickeyrsa' |
|---|
| 273 | | require 'pgp/packet/sigsubpacket' |
|---|
| 274 | | |
|---|
| 275 | | def keypacket(str, created) |
|---|
| 276 | | bytes = str.gsub(/([0-9a-f]{2})\s*/) { [$1].pack("H*") } |
|---|
| 277 | | n = PGP::MPI.decode(bytes) |
|---|
| 278 | | e = PGP::MPI.decode(bytes[258..-1]) |
|---|
| 279 | | packet = PGP::Packet::PublicKeyRSA.new(1) |
|---|
| 280 | | packet.n = n |
|---|
| 281 | | packet.e = e |
|---|
| 282 | | packet.keycreated = created |
|---|
| 283 | | packet |
|---|
| 284 | | end |
|---|
| 285 | | |
|---|
| 286 | | firstpacket = "08 00 d1 95 08 11 af |
|---|
| 287 | | 20 47 02 36 88 f0 4b 29 1f 13 67 83 31 81 4b 78 |
|---|
| 288 | | e3 de d5 98 3b 9d b1 30 64 43 28 76 4b 3d 6c 05 |
|---|
| 289 | | be c2 1d 8d a5 ae f5 ef ea 4e b8 cd 78 69 25 ca |
|---|
| 290 | | db 61 1d 17 06 d6 fe 46 51 24 85 49 21 59 9c 31 |
|---|
| 291 | | 6c 37 5c 9c b8 16 20 8b 40 3e c4 84 4b dd 60 6c |
|---|
| 292 | | dc f0 48 64 8c 60 6e 6f 28 08 18 db 1c 92 b9 13 |
|---|
| 293 | | 4b 3c 87 55 98 11 4e db 13 bf 7c 62 02 f4 67 90 |
|---|
| 294 | | 80 55 38 0c 90 00 99 13 55 ee ae c5 30 f4 e4 3d |
|---|
| 295 | | 5c ae 81 34 18 98 89 09 ab 55 83 55 ef d0 8c a4 |
|---|
| 296 | | 77 67 a5 cd ff 37 e5 04 41 a2 fe 8b 96 cc 61 79 |
|---|
| 297 | | 1c a7 b7 4c 82 86 60 9f be 56 1e 06 06 57 5a c9 |
|---|
| 298 | | 76 4d 0c 8b 74 41 04 4e f7 ba 24 7d f3 54 2a 67 |
|---|
| 299 | | 23 fa 38 d8 b5 8c 25 9e 2d 2e 22 7a 2f 08 ba df |
|---|
| 300 | | cd cd c8 a7 85 75 8c a0 a5 61 c7 9c 22 93 aa 56 |
|---|
| 301 | | 3c ca f6 d9 04 f0 52 80 13 24 50 a1 86 10 58 c3 |
|---|
| 302 | | bd f0 58 fa 24 ae 56 90 f3 dc 81 00 11 01 00 01" |
|---|
| 303 | | |
|---|
| 304 | | fourthpacket = "08 00 b4 a7 d3 c9 cb 8b ca 59 77 30 cf 4b 0e f8 |
|---|
| 305 | | ce 91 76 c3 0c cc 62 5f 3b d0 f6 6b 08 86 c6 0f |
|---|
| 306 | | 3f 2a e1 f7 ea a1 64 7f eb b5 aa c6 01 86 0d 00 |
|---|
| 307 | | fe 4f 84 0f d8 b1 1d 5b bc 28 42 21 18 e1 1b 67 |
|---|
| 308 | | d3 94 4f 70 d8 ad 8d 01 6a 4f 69 95 55 8c d8 70 |
|---|
| 309 | | 56 fe 71 1f a7 91 43 11 02 12 6d d1 47 5e c9 4f |
|---|
| 310 | | 2a d2 ff 1f 8a 6a 31 7c 74 96 df b2 77 0b 7d 74 |
|---|
| 311 | | 71 ad 14 2d 57 e7 09 c7 d3 49 d8 48 81 4b 57 ae |
|---|
| 312 | | 33 5f 64 87 77 e8 c4 41 7b 74 14 c8 8e c6 49 c0 |
|---|
| 313 | | 2e 7a ae ea ee 46 65 dd d4 2e 6c d9 4a 62 fb 6d |
|---|
| 314 | | fc d5 68 c9 a9 dd 34 df 79 da 85 f3 89 b9 88 b8 |
|---|
| 315 | | ac dd a6 b7 c8 99 b2 2f dc 5e bb ed 31 9a f7 2e |
|---|
| 316 | | 87 3e 6f 75 be 39 fb c2 31 09 12 20 fa 4d b0 ab |
|---|
| 317 | | c5 df 11 a2 39 4c cc 66 4b a0 3f 50 55 1c 2c 92 |
|---|
| 318 | | b5 b2 cd 61 3c b2 e0 1b 09 b1 6f 6a d7 d4 72 6d |
|---|
| 319 | | 79 37 83 fa a8 fb 01 29 5f f3 6e 17 b9 88 92 f5 |
|---|
| 320 | | d2 ab 00 11 01 00 01" |
|---|
| 321 | | |
|---|
| 322 | | mainkey = keypacket(firstpacket, 0x416674d2) |
|---|
| 323 | | subkey = keypacket(fourthpacket, 0x416674d4) |
|---|
| 324 | | |
|---|
| 325 | | d = PGP::Packet::Signature.new(0x18, 1, 2) |
|---|
| 326 | | d.target = mainkey.dump + subkey.dump |
|---|
| 327 | | d.hashedsubpacket << PGP::Packet::SigSubPacket::CreationTime.new(0x416674d4) |
|---|
| 328 | | # d.hashedsubpacket << PGP::Packet::SigSubPacket::PreferredSkeyAlgorithm.new(2) |
|---|
| 329 | | # d.hashedsubpacket << PGP::Packet::SigSubPacket::PrimaryUserID.new(true) |
|---|
| 330 | | d.hashedsubpacket << PGP::Packet::SigSubPacket::KeyFlags.new(0x0c) |
|---|
| 331 | | # d.hashedsubpacket << PGP::Packet::SigSubPacket::Features.new(0x01) |
|---|
| 332 | | d.unhashedsubpacket << PGP::Packet::SigSubPacket::IssuerKeyID.new([0xf0, 0x13, 0x92, 0x70, 0x3a, 0x80, 0x64, 0x90].pack("c*")) |
|---|
| 333 | | puts PGP::HexDump.encode(d.dump) |
|---|
| 334 | | |
|---|
| 335 | | p "---" |
|---|
| 336 | | |
|---|
| 337 | | name = "NAKAMURA, Hiroshi <cic@example.org>" |
|---|
| 338 | | d = PGP::Packet::Signature.new(0x10, 1, 2) |
|---|
| 339 | | d.hashedsubpacket << PGP::Packet::SigSubPacket::CreationTime.new(0x416674d3) |
|---|
| 340 | | d.hashedsubpacket << PGP::Packet::SigSubPacket::PreferredSkeyAlgorithm.new(2) |
|---|
| 341 | | d.hashedsubpacket << PGP::Packet::SigSubPacket::PrimaryUserID.new(true) |
|---|
| 342 | | d.hashedsubpacket << PGP::Packet::SigSubPacket::KeyFlags.new(0x03) |
|---|
| 343 | | d.hashedsubpacket << PGP::Packet::SigSubPacket::Features.new(0x01) |
|---|
| 344 | | d.unhashedsubpacket << PGP::Packet::SigSubPacket::IssuerKeyID.new([0xf0, 0x13, 0x92, 0x70, 0x3a, 0x80, 0x64, 0x90].pack("c*")) |
|---|
| 345 | | d.target = mainkey.dump + [0xb4].pack("c") + [name.length].pack("N") + name |
|---|
| 346 | | puts PGP::HexDump.encode(d.dump) |
|---|
| 347 | | end |
|---|