github.com/lestrrat-go/jwx/v2@v2.0.21/jwe/gh402_test.go (about)

     1  package jwe_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/lestrrat-go/jwx/v2/internal/json"
     8  	"github.com/lestrrat-go/jwx/v2/jwa"
     9  	"github.com/lestrrat-go/jwx/v2/jwe"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  // Pin represents the structured clevis data which can be used to decrypt the jwe message
    14  type Pin struct {
    15  	Pin     string      `json:"pin"`
    16  	Tang    *TangPin    `json:"tang,omitempty"`
    17  	Tpm2    *Tpm2Pin    `json:"tpm2,omitempty"`
    18  	Sss     *SssPin     `json:"sss,omitempty"`
    19  	Yubikey *YubikeyPin `json:"yubikey,omitempty"`
    20  }
    21  
    22  type TangPin struct {
    23  	Advertisement *json.RawMessage `json:"adv,omitempty"`
    24  	URL           string           `json:"url"`
    25  }
    26  
    27  type Tpm2Pin struct {
    28  	Hash    string `json:"hash,omitempty"`
    29  	Key     string `json:"key,omitempty"`
    30  	JwkPub  string `json:"jwk_pub,omitempty"`
    31  	JwkPriv string `json:"jwk_priv,omitempty"`
    32  	PcrBank string `json:"pcr_bank,omitempty"`
    33  	PcrIds  string `json:"pcr_ids,omitempty"`
    34  }
    35  
    36  type SssPin struct {
    37  	Jwe       []string `json:"jwe"`
    38  	Threshold int      `json:"t"`
    39  	Prime     string   `json:"p"`
    40  }
    41  
    42  type YubikeyPin struct {
    43  	Type      string     `json:"type"`
    44  	Challenge string     `json:"chalelenge"`
    45  	Slot      int        `json:"slot"`
    46  	Kdf       YubikeyKdf `json:"kdf"`
    47  }
    48  
    49  type YubikeyKdf struct {
    50  	Type       string `json:"type"`
    51  	Hash       string `json:"hash"`
    52  	Iterations int    `json:"iter"`
    53  	Salt       string `json:"salt"`
    54  }
    55  
    56  func TestGH402(t *testing.T) {
    57  	key := []byte{195, 170, 42, 171, 98, 176, 98, 162, 57, 170, 62, 69, 175, 209, 200, 151, 81, 135, 63, 43, 93, 20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wb2NrZHpRbW94VUNJc0lua2lPaUpCVTJGVVYxY3RSRk5ZVVhObFgxUmxibDg0VkdkVmFrWTNVRWxRTm5wcVpUUmxSbk55YkY5WFRESkhNRGwzTFROalYzVlRlVlZmUzFvemF6VndTVlp0TlZkaU1tcGlXREptV2sxWmVFNVpRbDh5Vm10d1QxWnVJbjBzSW10cFpDSTZJbEk0YWtWSk1YQlRNVWxoY0hWVVZHTktObGhJWkROWFUzbGZRbmhXU1hWb1VVeDFVekJwYjJkU09UUWlmUS4uTEk2ZC1TNUlYSDRIY2lxeS5ESWl3M1hFeXlaMVZWZDFPcWYwS1pJeGZrUWtnZXo4bXl2N0dfZGFMOWxIdjVFVlFMQzREVG9PMWF6UDQ5SDNGUk5PRHZIcXBmaWp1a3VDX2JmLVZldy41NGpyZnZWdEYxR3ItYU9TVEFjSWV3Il0sInAiOiI0NERteG1EZVFiWTJ3eHpIYm9PODFkbTBCbENNcVJzeEtLQ0NDQWo4TVVjIiwidCI6M319LCJlbmMiOiJBMjU2R0NNIn0..zz3fUXsiaME2cSoy.LTQovHUvDP4MXT2_sHgf_cM2gicobD5kGXEl5eY.MK3Lf6IwaoVUvCTp1Q5VOA"
    59  
    60  	decrypt := func(customField bool) {
    61  		t.Helper()
    62  		m := jwe.NewMessage()
    63  		// Test WithPostParse while we're at it
    64  		plain, err := jwe.Decrypt([]byte(data),
    65  			// This is a really cheesy way of creating a jwa.KeyEncryptionAlgorithm
    66  			// but a bogus one.
    67  			jwe.WithKey(jwa.KeyEncryptionAlgorithm("invalid algorithm"), nil),
    68  			jwe.WithMessage(m),
    69  			jwe.WithKeyProvider(jwe.KeyProviderFunc(func(_ context.Context, sink jwe.KeySink, _ jwe.Recipient, _ *jwe.Message) error {
    70  				sink.Key(jwa.DIRECT, key)
    71  				return nil
    72  			})),
    73  		)
    74  
    75  		if !assert.NoError(t, err, `jwe.Decrypt should succeed`) {
    76  			return
    77  		}
    78  
    79  		if string(plain) != "testing Shamir Secret Sharing" {
    80  			t.Errorf("expected 'testing Shamir Secret Sharing', got %s", string(plain))
    81  			return
    82  		}
    83  
    84  		if customField {
    85  			if !assert.NotNil(t, m.ProtectedHeaders(), `m.ProtectedHeaders should be non-nil`) {
    86  				return
    87  			}
    88  
    89  			v, ok := m.ProtectedHeaders().Get("clevis")
    90  			if !assert.True(t, ok, `m.Get("clevis") should be true`) {
    91  				return
    92  			}
    93  
    94  			if !assert.IsType(t, Pin{}, v, `result of m.Get("clevis") should be an instance of Pin{}`) {
    95  				return
    96  			}
    97  		}
    98  	}
    99  	decrypt(false)
   100  
   101  	// register field deserialized and run decryption again
   102  	jwe.RegisterCustomField("clevis", Pin{})
   103  	decrypt(true) // used to fail before, but this should pass
   104  }