Class: CyberplatPKI::PrivateKeyPacket
Instance Attribute Summary
Attributes inherited from KeyPacket
#algorithm, #key, #serial, #timestamp, #valid_days
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Packet
save
Class Method Details
.load(io, context) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/cyberplat_pki/private_key_packet.rb', line 3
def self.load(io, context)
key = super
cipher = io.readbyte
raise "CyberplatPKI: CRYPT_ERR_INVALID_PACKET_FORMAT (unsupported private key cipher: #{cipher})" if cipher != 1
iv = io.read 8
context.decrypt iv
public_key = key.key
key.key = OpenSSL::PKey::RSA.new
io.cipher = context
io.checksum = 0
key.key.d = io.read_mpi
key.key.p = io.read_mpi
key.key.q = io.read_mpi
dummy = io.read_mpi
calculated_checksum = io.checksum
io.checksum = nil
io.cipher = nil
checksum, = io.read(2).unpack("n")
raise "CyberplatPKI: CRYPT_ERR_INVALID_PASSWD (invalid MPI checksum. Expected #{checksum.to_s 16}, calculated #{calculated_checksum.to_s 16})" if checksum != calculated_checksum
key.key.dmp1 = key.key.d % (key.key.p - 1)
key.key.dmq1 = key.key.d % (key.key.q - 1)
key.key.iqmp = key.key.q.mod_inverse key.key.p
key.key.n = public_key.n
key.key.e = public_key.e
key
end
|
Instance Method Details
#save(io, context) ⇒ Object
42
43
44
45
46
|
# File 'lib/cyberplat_pki/private_key_packet.rb', line 42
def save(io, context)
super
raise NotImplementedError, "CyberplatPKI: PrivateKeyPacket#save is not implemented"
end
|