07ef97f5daa11c498f17894abfc379bf8079ff1f
[epoint] / patches / sig.diff
1 diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/signature.go
2 --- a/src/pkg/crypto/openpgp/packet/signature.go        Thu Nov 24 08:51:47 2011 -0800
3 +++ b/src/pkg/crypto/openpgp/packet/signature.go        Wed Nov 30 21:54:03 2011 +0100
4 @@ -163,7 +163,7 @@
5  const (
6         creationTimeSubpacket        signatureSubpacketType = 2
7         signatureExpirationSubpacket signatureSubpacketType = 3
8 -       keyExpirySubpacket           signatureSubpacketType = 9
9 +       keyExpirationSubpacket       signatureSubpacketType = 9
10         prefSymmetricAlgosSubpacket  signatureSubpacketType = 11
11         issuerSubpacket              signatureSubpacketType = 16
12         prefHashAlgosSubpacket       signatureSubpacketType = 21
13 @@ -235,7 +235,7 @@
14                 }
15                 sig.SigLifetimeSecs = new(uint32)
16                 *sig.SigLifetimeSecs = binary.BigEndian.Uint32(subpacket)
17 -       case keyExpirySubpacket:
18 +       case keyExpirationSubpacket:
19                 // Key expiration time, section 5.2.3.6
20                 if !isHashed {
21                         return
22 @@ -541,10 +541,7 @@
23  
24  func (sig *Signature) buildSubpackets() (subpackets []outputSubpacket) {
25         creationTime := make([]byte, 4)
26 -       creationTime[0] = byte(sig.CreationTime >> 24)
27 -       creationTime[1] = byte(sig.CreationTime >> 16)
28 -       creationTime[2] = byte(sig.CreationTime >> 8)
29 -       creationTime[3] = byte(sig.CreationTime)
30 +       binary.BigEndian.PutUint32(creationTime, sig.CreationTime)
31         subpackets = append(subpackets, outputSubpacket{true, creationTimeSubpacket, false, creationTime})
32  
33         if sig.IssuerKeyId != nil {
34 @@ -553,5 +550,56 @@
35                 subpackets = append(subpackets, outputSubpacket{true, issuerSubpacket, false, keyId})
36         }
37  
38 +       if sig.SigLifetimeSecs != nil && *sig.SigLifetimeSecs != 0 {
39 +               sigLifetime := make([]byte, 4)
40 +               binary.BigEndian.PutUint32(sigLifetime, *sig.SigLifetimeSecs)
41 +               subpackets = append(subpackets, outputSubpacket{true, signatureExpirationSubpacket, false, sigLifetime})
42 +       }
43 +
44 +       // The following subpackets may only appear in self-signatures
45 +
46 +       if sig.KeyLifetimeSecs != nil && *sig.KeyLifetimeSecs != 0 {
47 +               keyLifetime := make([]byte, 4)
48 +               binary.BigEndian.PutUint32(keyLifetime, *sig.KeyLifetimeSecs)
49 +               subpackets = append(subpackets, outputSubpacket{true, keyExpirationSubpacket, false, keyLifetime})
50 +       }
51 +
52 +       if sig.IsPrimaryId != nil && *sig.IsPrimaryId {
53 +               subpackets = append(subpackets, outputSubpacket{true, primaryUserIdSubpacket, false, []byte{1}})
54 +       }
55 +
56 +       // []byte slices of preferred algorithms are not copied
57 +
58 +       if len(sig.PreferredSymmetric) > 0 {
59 +               subpackets = append(subpackets, outputSubpacket{true, prefSymmetricAlgosSubpacket, false, sig.PreferredSymmetric})
60 +       }
61 +
62 +       if len(sig.PreferredHash) > 0 {
63 +               subpackets = append(subpackets, outputSubpacket{true, prefHashAlgosSubpacket, false, sig.PreferredHash})
64 +       }
65 +
66 +       if len(sig.PreferredCompression) > 0 {
67 +               subpackets = append(subpackets, outputSubpacket{true, prefCompressionSubpacket, false, sig.PreferredCompression})
68 +       }
69 +
70 +       // The Key Flags subpacket may only appear in self-signatures or certification signatures
71 +
72 +       if sig.FlagsValid {
73 +               flags := byte(0)
74 +               if sig.FlagCertify {
75 +                       flags |= 1
76 +               }
77 +               if sig.FlagSign {
78 +                       flags |= 2
79 +               }
80 +               if sig.FlagEncryptCommunications {
81 +                       flags |= 4
82 +               }
83 +               if sig.FlagEncryptStorage {
84 +                       flags |= 8
85 +               }
86 +               subpackets = append(subpackets, outputSubpacket{true, keyFlagsSubpacket, false, []byte{flags}})
87 +       }
88 +
89         return
90  }