Skip to content

Commit 8650228

Browse files
Merge pull request #19 from spiegel-im-spiegel/support-rfc4880bis
Support rfc4880bis
2 parents 72616bc + 234a7c3 commit 8650228

34 files changed

+617
-399
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
- Based on [pgpdump](https://github.com/kazu-yamamoto/pgpdump)
1010
- Provide [golang](https://golang.org/) package and command-line Interface
11-
- Output with [TOML](https://github.com/toml-lang/toml) (or [JSON](https://tools.ietf.org/html/rfc7159)) format
11+
- Output with plain text, [TOML](https://github.com/toml-lang/toml), and [JSON](https://tools.ietf.org/html/rfc7159) format
1212
- Support [RFC 5581] and [RFC 6637]
1313

1414
## Install

packet/pubkey/parse_secplain.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ func (p *Pubkey) ParseSecPlain(parent *info.Item) error {
4646
info.DumpStr(values.DumpBytes(b, p.cxt.Debug()).String()),
4747
))
4848
}
49-
switch p.reader.Rest() {
50-
case 2: //checksum
51-
parent.Add(values.RawData(p.reader, "Checksum", true))
52-
case 20: //SHA-1 hash
53-
parent.Add(values.RawData(p.reader, "SHA-1 hash", true))
54-
default:
55-
parent.Add(values.RawData(p.reader, "Other hash", true))
49+
chk, err := p.reader.ReadBytes(2)
50+
if err != nil {
51+
return errors.Wrap(err, "error in pubkey.Pubkey.ParseSecPlain() function (Checksum)")
5652
}
53+
parent.Add(info.NewItem(
54+
info.Name("Checksum"),
55+
info.DumpStr(values.DumpBytes(chk, true).String()),
56+
))
5757
return nil
5858
}
5959

@@ -126,7 +126,7 @@ func (p *Pubkey) eddsaSec(item *info.Item) error {
126126
return nil
127127
}
128128

129-
/* Copyright 2016 Spiegel
129+
/* Copyright 2016-2018 Spiegel
130130
*
131131
* Licensed under the Apache License, Version 2.0 (the "License");
132132
* you may not use this file except in compliance with the License.

packet/tags/pubkey.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (p *pubkeyInfo) parseV5(parent *info.Item) error {
119119
return errors.Wrap(err, "error in tags.pubkey,parseV5() function (key material data)")
120120
}
121121
// [10] series of multiprecision integers comprising the key material.
122-
return pubkey.New(p.cxt, p.pubID, reader.New(b)).ParsePub(parent)
122+
return pubkey.New(p.cxt, p.pubID, reader.New(b)).ParsePub(parent) //TODO: new logic for key material
123123
}
124124

125125
//PubID returns pubID

packet/tags/seckey.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (p *seckeyInfo) Parse(parent *info.Item) error {
3535
switch sid {
3636
case 0:
3737
parent.Note = "the secret-key data is not encrypted."
38-
parent.Add(p.pubVer.ToItem(p.cxt.Debug()))
38+
//parent.Add(p.pubVer.ToItem(p.cxt.Debug()))
3939
if !p.pubVer.IsUnknown() {
4040
if err := pubkey.New(p.cxt, p.pubID, p.reader).ParseSecPlain(parent); err != nil {
4141
return err

packet/tags/sub27.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ func newSub27(cxt *context.Context, subID values.SuboacketID, body []byte) Subs
2020
// Parse parsing Key Flags Sub-packet
2121
func (s *sub27) Parse() (*info.Item, error) {
2222
rootInfo := s.subID.ToItem(s.reader, s.cxt.Debug())
23+
24+
//First octet
2325
flag, err := s.reader.ReadByte()
2426
if err != nil {
2527
return nil, err
@@ -32,6 +34,18 @@ func (s *sub27) Parse() (*info.Item, error) {
3234
rootInfo.Add(values.Flag2Item(flag&0x20, "This key may be used for authentication."))
3335
rootInfo.Add(values.Flag2Item(flag&0x40, fmt.Sprintf("Unknown flag1(%#02x)", flag&0x40)))
3436
rootInfo.Add(values.Flag2Item(flag&0x80, "The private component of this key may be in the possession of more than one person."))
37+
38+
//second octet
39+
if s.reader.Rest() > 0 {
40+
flag, err := s.reader.ReadByte()
41+
if err != nil {
42+
return nil, err
43+
}
44+
rootInfo.Add(values.Flag2Item(flag&0x04, "This key may be used as an additional decryption subkey (ADSK)."))
45+
rootInfo.Add(values.Flag2Item(flag&0xfb, fmt.Sprintf("Unknown flag2(%#02x)", flag&0xfb)))
46+
}
47+
48+
//other flags
3549
if s.reader.Rest() > 0 {
3650
flags, _ := s.reader.Read2EOF()
3751
for i, flag := range flags {

packet/tags/sub34.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import (
77
"github.com/spiegel-im-spiegel/gpgpdump/packet/values"
88
)
99

10-
//subReserved class for Reserved Sub-packet
10+
//subReserved class for Preferred AEAD Algorithms Sub-packet
1111
type sub34 subInfo
1212

13-
//newSubReserved return subReserved instance
13+
//newSubReserved return sub34 instance
1414
func newSub34(cxt *context.Context, subID values.SuboacketID, body []byte) Subs {
1515
return &sub34{cxt: cxt, subID: subID, reader: reader.New(body)}
1616
}
1717

18-
// Parse parsing Reserved Sub-packet
18+
// Parse parsing Preferred AEAD Algorithms Sub-packet
1919
func (s *sub34) Parse() (*info.Item, error) {
2020
rootInfo := s.subID.ToItem(s.reader, s.cxt.Debug())
2121
return rootInfo, nil
2222
}
2323

24-
/* Copyright 2016 Spiegel
24+
/* Copyright 2018 Spiegel
2525
*
2626
* Licensed under the Apache License, Version 2.0 (the "License");
2727
* you may not use this file except in compliance with the License.

packet/tags/subs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func NewSubs(cxt *context.Context, osp *openpgp.OpaqueSubpacket, tagID values.Ta
8181
return nil
8282
}
8383

84-
/* Copyright 2016 Spiegel
84+
/* Copyright 2016-2018 Spiegel
8585
*
8686
* Licensed under the Apache License, Version 2.0 (the "License");
8787
* you may not use this file except in compliance with the License.

packet/tags/tag01.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ func (t *tag01) Parse() (*info.Item, error) {
4343
if err := pubkey.New(t.cxt, values.PubID(pubid), t.reader).ParseSes(rootInfo); err != nil {
4444
return rootInfo, err
4545
}
46+
47+
if t.reader.Rest() > 0 {
48+
rootInfo.Add(values.RawData(t.reader, "Unknown data", t.cxt.Debug()))
49+
}
4650
return rootInfo, nil
4751
}
4852

packet/tags/tag01_test.go

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55

66
"github.com/spiegel-im-spiegel/gpgpdump/options"
77
"github.com/spiegel-im-spiegel/gpgpdump/packet/context"
8+
"github.com/spiegel-im-spiegel/gpgpdump/packet/reader"
9+
"github.com/spiegel-im-spiegel/gpgpdump/packet/values"
810

911
openpgp "golang.org/x/crypto/openpgp/packet"
1012
)
@@ -29,30 +31,45 @@ const (
2931
)
3032

3133
func TestTag01(t *testing.T) {
32-
op := &openpgp.OpaquePacket{Tag: 1, Contents: tag01Body}
33-
cxt := context.NewContext(options.New(
34-
options.Set(options.DebugOpt, true),
35-
options.Set(options.IntegerOpt, true),
36-
options.Set(options.MarkerOpt, true),
37-
options.Set(options.LiteralOpt, true),
38-
options.Set(options.PrivateOpt, true),
39-
options.Set(options.UTCOpt, true),
40-
))
41-
i, err := NewTag(op, cxt).Parse()
42-
if err != nil {
43-
t.Errorf("NewTag() = %v, want nil error.", err)
44-
return
34+
testCases := []struct {
35+
tag uint8
36+
content []byte
37+
ktm []byte
38+
cxt context.SymAlgMode
39+
res string
40+
}{
41+
{tag: 1, content: tag01Body, ktm: nil, cxt: context.ModePubEnc, res: tag01Redult},
4542
}
46-
if cxt.AlgMode() != context.ModePubEnc {
47-
t.Errorf("Options.Mode = %v, want \"%v\".", cxt.AlgMode(), context.ModePubEnc)
48-
}
49-
str := i.String()
50-
if str != tag01Redult {
51-
t.Errorf("Tag.String = \"%s\", want \"%s\".", str, tag01Redult)
43+
for _, tc := range testCases {
44+
op := &openpgp.OpaquePacket{Tag: tc.tag, Contents: tc.content}
45+
cxt := context.NewContext(options.New(
46+
options.Set(options.DebugOpt, true),
47+
options.Set(options.IntegerOpt, true),
48+
options.Set(options.MarkerOpt, true),
49+
options.Set(options.LiteralOpt, true),
50+
options.Set(options.PrivateOpt, true),
51+
options.Set(options.UTCOpt, true),
52+
))
53+
if tc.ktm != nil {
54+
tm, _ := values.NewDateTime(reader.New(tc.ktm), cxt.UTC())
55+
cxt.KeyCreationTime = tm
56+
}
57+
i, err := NewTag(op, cxt).Parse()
58+
if err != nil {
59+
t.Errorf("NewTag() = %v, want nil error.", err)
60+
return
61+
}
62+
if cxt.AlgMode() != tc.cxt {
63+
t.Errorf("Options.Mode = %v, want \"%v\".", cxt.AlgMode(), tc.cxt)
64+
}
65+
res := i.String()
66+
if res != tc.res {
67+
t.Errorf("Tag.String = \"%s\", want \"%s\".", res, tc.res)
68+
}
5269
}
5370
}
5471

55-
/* Copyright 2017 Spiegel
72+
/* Copyright 2017,2018 Spiegel
5673
*
5774
* Licensed under the Apache License, Version 2.0 (the "License");
5875
* you may not use this file except in compliance with the License.

packet/tags/tag02.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (t *tag02) Parse() (*info.Item, error) {
4747
}
4848

4949
if t.reader.Rest() > 0 {
50-
rootInfo.Add(values.RawData(t.reader, "Rest", t.cxt.Debug()))
50+
rootInfo.Add(values.RawData(t.reader, "Unknown data", t.cxt.Debug()))
5151
}
5252
return rootInfo, nil
5353
}

0 commit comments

Comments
 (0)