-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathocsp.go
66 lines (56 loc) · 1.36 KB
/
ocsp.go
1
2
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package sct
import "crypto/x509/pkix"
import "encoding/binary"
var OCSPSCToid []int = []int{1, 3, 6, 1, 4, 1, 11129, 2, 4, 5}
func CreateOCSPResponse(scts []SignedCertificateTimestamp) (ocspret pkix.Extension, errorret error) {
if len(scts) == 0 {
errorret = NO_SCTS_GIVEN
return
}
// Determine required length
sctoutlen := 6
for _, ct := range scts {
n, err := WriteOutHere(ct, nil)
if n == 0 {
errorret = err
return
}
sctoutlen += 2 + n
}
if (sctoutlen - 4) > 0xFFFF {
errorret = SCT_TOO_LARGE
return
}
output := make([]byte, sctoutlen)
binary.BigEndian.PutUint16(output[4:6], uint16(sctoutlen-6))
sctpos := 6
for _, ct := range scts {
n, _ := WriteOutHere(ct, nil)
binary.BigEndian.PutUint16(output[sctpos:sctpos+2], uint16(n))
sctpos += 2
_, err := WriteOutHere(ct, output[sctpos:sctpos+n])
if err != nil {
errorret = err
return
}
sctpos += n
}
//Save 10 Allocations by performing a super simple version of ASN1 encoding
if (sctoutlen - 4) <= 0x7F {
output[2] = 4
output[3] = byte(sctoutlen - 4)
output = output[2:]
} else if (sctoutlen - 4) <= 0xFF {
output[1] = 4
output[2] = 0x81
output[3] = byte(sctoutlen - 4)
output = output[1:]
} else {
output[0] = 4
output[1] = 0x82
binary.BigEndian.PutUint16(output[2:4], uint16(sctoutlen-4))
}
ocspret.Id = OCSPSCToid
ocspret.Value = output
return
}