Start implementation of revoke action
This commit is contained in:
parent
38566f35ef
commit
2de9771472
9 changed files with 739 additions and 57 deletions
|
@ -2,7 +2,9 @@ package datastructures
|
|||
|
||||
import "encoding/binary"
|
||||
|
||||
func encode24BitLength(data []byte) []byte {
|
||||
const signerTimeFormat = "010203042006.05"
|
||||
|
||||
func Encode24BitLength(data []byte) []byte {
|
||||
lengthBytes := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(lengthBytes, uint32(len(data)))
|
||||
return lengthBytes[1:]
|
||||
|
|
|
@ -3,23 +3,24 @@ package datastructures
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.cacert.org/cacert-gosigner/shared"
|
||||
)
|
||||
|
||||
type SignerRequest struct {
|
||||
Version uint8
|
||||
Action shared.Action
|
||||
System uint8
|
||||
Root uint8
|
||||
Configuration uint8
|
||||
Parameter1 uint8
|
||||
Parameter2 uint16
|
||||
Parameter3 uint8
|
||||
Content1 string
|
||||
Content2 string
|
||||
Content3 string
|
||||
Version uint8
|
||||
Action shared.Action
|
||||
System shared.CryptoSystemId
|
||||
Root shared.CryptoSystemRootId
|
||||
Profile shared.CertificateProfileId
|
||||
MdAlgorithm shared.MessageDigestAlgorithmId
|
||||
Days uint16
|
||||
Spkac uint8
|
||||
Content1 string
|
||||
Content2 string
|
||||
Content3 string
|
||||
}
|
||||
|
||||
func SignerRequestFromData(blockData []byte) (*SignerRequest, error) {
|
||||
|
@ -39,42 +40,66 @@ func SignerRequestFromData(blockData []byte) (*SignerRequest, error) {
|
|||
content3 := string(contentBytes[3+content3Offset : 3+content3Offset+content3Length])
|
||||
|
||||
return &SignerRequest{
|
||||
Version: headerBytes[0],
|
||||
Action: shared.Action(headerBytes[1]),
|
||||
System: headerBytes[2],
|
||||
Root: headerBytes[3],
|
||||
Configuration: headerBytes[4],
|
||||
Parameter1: headerBytes[5],
|
||||
Parameter2: binary.BigEndian.Uint16([]byte{headerBytes[6], headerBytes[7]}),
|
||||
Parameter3: headerBytes[8],
|
||||
Content1: content1,
|
||||
Content2: content2,
|
||||
Content3: content3,
|
||||
Version: headerBytes[0],
|
||||
Action: shared.Action(headerBytes[1]),
|
||||
System: shared.CryptoSystemId(headerBytes[2]),
|
||||
Root: shared.CryptoSystemRootId(headerBytes[3]),
|
||||
Profile: shared.CertificateProfileId(headerBytes[4]),
|
||||
MdAlgorithm: shared.MessageDigestAlgorithmId(headerBytes[5]),
|
||||
Days: binary.BigEndian.Uint16([]byte{headerBytes[6], headerBytes[7]}),
|
||||
Spkac: headerBytes[8],
|
||||
Content1: content1,
|
||||
Content2: content2,
|
||||
Content3: content3,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r SignerRequest) Serialize() []byte {
|
||||
func (r *SignerRequest) Serialize() []byte {
|
||||
parameter2Bytes := make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(parameter2Bytes, r.Parameter2)
|
||||
binary.BigEndian.PutUint16(parameter2Bytes, r.Days)
|
||||
headerBytes := bytes.Join([][]byte{
|
||||
{r.Version, byte(r.Action), r.System, r.Root, r.Configuration, r.Parameter1},
|
||||
parameter2Bytes, {r.Parameter3}}, []byte{})
|
||||
{
|
||||
r.Version,
|
||||
byte(r.Action),
|
||||
byte(r.System),
|
||||
byte(r.Root),
|
||||
byte(r.Profile),
|
||||
byte(r.MdAlgorithm),
|
||||
},
|
||||
parameter2Bytes, {r.Spkac}}, []byte{})
|
||||
content1Bytes := []byte(r.Content1)
|
||||
content2Bytes := []byte(r.Content2)
|
||||
content3Bytes := []byte(r.Content3)
|
||||
blockBytes := bytes.Join([][]byte{
|
||||
encode24BitLength(headerBytes), headerBytes,
|
||||
encode24BitLength(content1Bytes), content1Bytes,
|
||||
encode24BitLength(content2Bytes), content2Bytes,
|
||||
encode24BitLength(content3Bytes), content3Bytes,
|
||||
Encode24BitLength(headerBytes), headerBytes,
|
||||
Encode24BitLength(content1Bytes), content1Bytes,
|
||||
Encode24BitLength(content2Bytes), content2Bytes,
|
||||
Encode24BitLength(content3Bytes), content3Bytes,
|
||||
}, []byte{})
|
||||
return bytes.Join([][]byte{encode24BitLength(blockBytes), blockBytes}, []byte{})
|
||||
return bytes.Join([][]byte{Encode24BitLength(blockBytes), blockBytes}, []byte{})
|
||||
}
|
||||
|
||||
func (r *SignerRequest) String() string {
|
||||
return fmt.Sprintf(
|
||||
"v:%d %s s:%d r:%d p:%d md:%d days:%d spkac:%d '%s' '%s' '%s'",
|
||||
r.Version,
|
||||
r.Action,
|
||||
r.System,
|
||||
r.Root,
|
||||
r.Profile,
|
||||
r.MdAlgorithm,
|
||||
r.Days,
|
||||
r.Spkac,
|
||||
r.Content1,
|
||||
r.Content2,
|
||||
r.Content3,
|
||||
)
|
||||
}
|
||||
|
||||
func NewNulRequest() *SignerRequest {
|
||||
return &SignerRequest{
|
||||
Version: shared.ProtocolVersion,
|
||||
Action: shared.ActionNul,
|
||||
Content1: time.Now().UTC().Format("010203042006.05"),
|
||||
Content1: time.Now().UTC().Format(signerTimeFormat),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,10 +62,20 @@ func (r SignerResponse) Serialize() []byte {
|
|||
content2Bytes := []byte(r.Content2)
|
||||
content3Bytes := []byte(r.Content3)
|
||||
blockBytes := bytes.Join([][]byte{
|
||||
encode24BitLength(headerBytes), headerBytes,
|
||||
encode24BitLength(content1Bytes), content1Bytes,
|
||||
encode24BitLength(content2Bytes), content2Bytes,
|
||||
encode24BitLength(content3Bytes), content3Bytes,
|
||||
Encode24BitLength(headerBytes), headerBytes,
|
||||
Encode24BitLength(content1Bytes), content1Bytes,
|
||||
Encode24BitLength(content2Bytes), content2Bytes,
|
||||
Encode24BitLength(content3Bytes), content3Bytes,
|
||||
}, []byte{})
|
||||
return bytes.Join([][]byte{encode24BitLength(blockBytes), blockBytes}, []byte{})
|
||||
return bytes.Join([][]byte{Encode24BitLength(blockBytes), blockBytes}, []byte{})
|
||||
}
|
||||
|
||||
func NewNulResponse(version byte) *SignerResponse {
|
||||
return &SignerResponse{
|
||||
Version: version,
|
||||
Action: shared.ActionNul,
|
||||
Content1: "",
|
||||
Content2: "",
|
||||
Content3: "",
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue