Jonathan Turner 9 år sedan
förälder
incheckning
d1e791c491
3 ändrade filer med 36 tillägg och 12 borttagningar
  1. 2 1
      README.md
  2. 33 10
      types/Ticket.go
  3. 1 1
      types/asnAppTag/constants.go

+ 2 - 1
README.md

@@ -25,4 +25,5 @@ This is work in progress and does not yet work...
 |-------|-------------|------------|
 | Cannot unmarshal into slice of asn1.RawValue | Yes | [https://github.com/golang/go/issues/17321](https://github.com/golang/go/issues/17321) |
 | Cannot marshal into a GeneralString | Yes - using https://github.com/jcmturner/asn1 | [encoding/asn1: cannot marshal into a GeneralString](https://github.com/golang/go/issues/18832) |
-| Cannot marshal into slice of strings and pass stringtype parameter tags to members | Yes - using https://github.com/jcmturner/asn1 |[encoding/asn1: cannot marshal into slice of strings and pass stringtype parameter tags to members](https://github.com/golang/go/issues/18834) |
+| Cannot marshal into slice of strings and pass stringtype parameter tags to members | Yes - using https://github.com/jcmturner/asn1 |[encoding/asn1: cannot marshal into slice of strings and pass stringtype parameter tags to members](https://github.com/golang/go/issues/18834) |
+| Cannot marshal with application tags | Yes | |

+ 33 - 10
types/Ticket.go

@@ -6,6 +6,8 @@ import (
 	"github.com/jcmturner/gokrb5/types/asnAppTag"
 	jtasn1 "github.com/jcmturner/asn1"
 	"time"
+	"os"
+	"encoding/hex"
 )
 
 // Reference: https://www.ietf.org/rfc/rfc4120.txt
@@ -62,9 +64,10 @@ func UnmarshalTicket(b []byte) (t Ticket, err error) {
 }
 
 func UnmarshalTicketsSequence(in asn1.RawValue) ([]Ticket, error) {
-	//fmt.Fprintf(os.Stderr, "Raw c: %v\n", in.Class)
-	//fmt.Fprintf(os.Stderr, "Raw  b: %v\n", in.Bytes)
-	//fmt.Fprintf(os.Stderr, "Raw fb: %v\n", in.FullBytes)
+	fmt.Fprintf(os.Stderr, "Raw c: %v is: %v t: %v\n", in.Class, in.IsCompound, in.Tag)
+	fmt.Fprintf(os.Stderr, "Raw  b: %v\n", in.Bytes)
+	fmt.Fprintf(os.Stderr, "Raw  b: %v\n", hex.EncodeToString(in.Bytes))
+	fmt.Fprintf(os.Stderr, "Raw fb: %v\n", in.FullBytes)
 	//This is a workaround to a asn1 decoding issue in golang - https://github.com/golang/go/issues/17321. It's not pretty I'm afraid
 	//We pull out raw values from the larger raw value (that is actually the data of the sequence of raw values) and track our position moving along the data.
 	b := in.Bytes
@@ -84,13 +87,33 @@ func UnmarshalTicketsSequence(in asn1.RawValue) ([]Ticket, error) {
 		p += len(raw.FullBytes)
 		tkts = append(tkts, t)
 	}
+	MarshalTicketSequence(tkts)
 	return tkts, nil
 }
 
-//func MarshalTicketSequence([]Ticket) (asn1.RawValue, error) {
-//	raw := asn1.RawValue{
-//		Class:      16,
-//		IsCompound: true,
-//	}
-//
-//}
+func MarshalTicketSequence(tkts []Ticket) (asn1.RawValue, error) {
+	raw := asn1.RawValue{
+		Class:      2,
+		IsCompound: true,
+		//Tag: 11,
+	}
+	var btkts []byte
+	for i, t := range tkts {
+		b, err := t.Marshal()
+		if err != nil {
+			return raw, fmt.Errorf("Error marshalling ticket number %d in seqence of tickets", i +1)
+		}
+		btkts = append(btkts, b...)
+	}
+	// The ASN1 wrapping consists of 2 bytes:
+	// 1st byte -> Identifier Octet - In this case an OCTET STRING (ASN TAG
+	// 2nd byte -> The length (this will be the size indicated in the input bytes + 2 for the additional bytes we add here.
+	// Application Tag:
+	//| Byte:       | 8                            | 7                          | 6                                         | 5 | 4 | 3 | 2 | 1             |
+	//| Value:      | 0                            | 1                          | 1                                         | From the RFC spec 4120        |
+	//| Explanation | Defined by the ASN1 encoding rules for an application tag | A value of 1 indicates a constructed type | The ASN Application tag value |
+	btkts = append([]byte{byte(len(btkts))}, btkts...)
+	fmt.Fprintf(os.Stderr, "mar: %+v", btkts)
+	raw.Bytes = btkts
+	return raw, nil
+}

+ 1 - 1
types/asnAppTag/constants.go

@@ -24,7 +24,7 @@ const (
 // This method adds that wrapping tag
 func AddASNAppTag(b []byte, tag int) []byte {
 	// The ASN1 wrapping consists of 2 bytes:
-	// 1st byte -> Application Tag
+	// 1st byte -> Identifier Octet - Application Tag
 	// 2nd byte -> The length (this will be the size indicated in the input bytes + 2 for the additional bytes we add here.
 	// Application Tag:
 	//| Byte:       | 8                            | 7                          | 6                                         | 5 | 4 | 3 | 2 | 1             |