88 "crypto/rand"
99 "crypto/sha256"
1010 "encoding/json"
11- "encoding/pem"
1211 "errors"
1312 "fmt"
1413 "io"
@@ -54,7 +53,7 @@ func TestEnroll(t *testing.T) {
5453 oidcExpiresAt := time .Now ()
5554 counter := uint (5 )
5655 ca , _ := dnapitest .NebulaCACert ()
57- caPEM , err := ca .MarshalToPEM ()
56+ caPEM , err := ca .MarshalPEM ()
5857 require .NoError (t , err )
5958
6059 ts .ExpectEnrollment (code , message .NetworkCurve25519 , func (req message.EnrollRequest ) []byte {
@@ -78,7 +77,7 @@ func TestEnroll(t *testing.T) {
7877 HostID : hostID ,
7978 Counter : counter ,
8079 Config : cfg ,
81- TrustedKeys : marshalCAPublicKey ( ca .Details . Curve , ca . Details . PublicKey ),
80+ TrustedKeys : ca .MarshalPublicKeyPEM ( ),
8281 Organization : message.HostOrgMetadata {
8382 ID : orgID ,
8483 Name : orgName ,
@@ -109,7 +108,7 @@ func TestEnroll(t *testing.T) {
109108 assert .Empty (t , ts .Errors ())
110109 assert .Equal (t , 0 , ts .RequestsRemaining ())
111110
112- tk , err := keys .NewTrustedKey (ed25519 .PublicKey (ca .Details . PublicKey ))
111+ tk , err := keys .NewTrustedKey (ed25519 .PublicKey (ca .PublicKey () ))
113112 require .NoError (t , err )
114113
115114 assert .Equal (t , hostID , creds .HostID )
@@ -129,7 +128,7 @@ func TestEnroll(t *testing.T) {
129128 }
130129 err = yaml .Unmarshal (cfg , & y )
131130 require .NoError (t , err )
132- _ , rest , err := cert .UnmarshalX25519PublicKey (y .Test .DHPubkey )
131+ _ , rest , _ , err := cert .UnmarshalPublicKeyFromPEM (y .Test .DHPubkey )
133132 assert .NoError (t , err )
134133 assert .Len (t , rest , 0 )
135134 assert .Equal (t , code , y .Test .Code )
@@ -182,7 +181,7 @@ func TestDoUpdate(t *testing.T) {
182181 t .Cleanup (func () { ts .Close () })
183182
184183 ca , caPrivkey := dnapitest .NebulaCACert ()
185- caPEM , err := ca .MarshalToPEM ()
184+ caPEM , err := ca .MarshalPEM ()
186185 require .NoError (t , err )
187186
188187 c := NewClient (useragent , ts .URL )
@@ -209,7 +208,7 @@ func TestDoUpdate(t *testing.T) {
209208 HostID : "foobar" ,
210209 Counter : 1 ,
211210 Config : cfg ,
212- TrustedKeys : marshalCAPublicKey ( ca .Details . Curve , ca . Details . PublicKey ),
211+ TrustedKeys : ca .MarshalPublicKeyPEM ( ),
213212 Organization : message.HostOrgMetadata {
214213 ID : "foobaz" ,
215214 Name : "foobar's foo org" ,
@@ -278,7 +277,7 @@ func TestDoUpdate(t *testing.T) {
278277 Config : dnapitest .NebulaCfg (caPEM ),
279278 Counter : 2 ,
280279 Nonce : dnapitest .GetNonce (r ),
281- TrustedKeys : marshalCAPublicKey ( ca .Details . Curve , ca . Details . PublicKey ),
280+ TrustedKeys : ca .MarshalPublicKeyPEM ( ),
282281 Organization : message.HostOrgMetadata {
283282 ID : "foobaz" ,
284283 Name : "foobar's foo org" ,
@@ -333,7 +332,7 @@ func TestDoUpdate(t *testing.T) {
333332 Config : dnapitest .NebulaCfg (caPEM ),
334333 Counter : 0 ,
335334 Nonce : dnapitest .GetNonce (r ),
336- TrustedKeys : marshalCAPublicKey ( ca .Details . Curve , ca . Details . PublicKey ),
335+ TrustedKeys : ca .MarshalPublicKeyPEM ( ),
337336 Organization : message.HostOrgMetadata {
338337 ID : "foobaz" ,
339338 Name : "foobar's foo org" ,
@@ -393,7 +392,7 @@ func TestDoUpdate(t *testing.T) {
393392 Config : dnapitest .NebulaCfg (caPEM ),
394393 Counter : 3 ,
395394 Nonce : dnapitest .GetNonce (r ),
396- TrustedKeys : marshalCAPublicKey ( ca .Details . Curve , ca . Details . PublicKey ),
395+ TrustedKeys : ca .MarshalPublicKeyPEM ( ),
397396 Organization : message.HostOrgMetadata {
398397 ID : orgID ,
399398 Name : orgName ,
@@ -453,7 +452,7 @@ func TestDoUpdate_P256(t *testing.T) {
453452 t .Cleanup (func () { ts .Close () })
454453
455454 ca , caPrivkey := dnapitest .NebulaCACertP256 ()
456- caPEM , err := ca .MarshalToPEM ()
455+ caPEM , err := ca .MarshalPEM ()
457456 require .NoError (t , err )
458457
459458 c := NewClient (useragent , ts .URL )
@@ -480,7 +479,7 @@ func TestDoUpdate_P256(t *testing.T) {
480479 HostID : "foobar" ,
481480 Counter : 1 ,
482481 Config : cfg ,
483- TrustedKeys : marshalCAPublicKey ( ca .Details . Curve , ca . Details . PublicKey ),
482+ TrustedKeys : ca .MarshalPublicKeyPEM ( ),
484483 Organization : message.HostOrgMetadata {
485484 ID : "foobaz" ,
486485 Name : "foobar's foo org" ,
@@ -638,7 +637,7 @@ func TestDoUpdate_P256(t *testing.T) {
638637 Config : dnapitest .NebulaCfg (caPEM ),
639638 Counter : 3 ,
640639 Nonce : dnapitest .GetNonce (r ),
641- TrustedKeys : marshalCAPublicKey ( ca .Details . Curve , ca . Details . PublicKey ),
640+ TrustedKeys : ca .MarshalPublicKeyPEM ( ),
642641 Organization : message.HostOrgMetadata {
643642 ID : "foobaz" ,
644643 Name : "foobar's foo org" ,
@@ -693,7 +692,7 @@ func TestCommandResponse(t *testing.T) {
693692 t .Cleanup (func () { ts .Close () })
694693
695694 ca , _ := dnapitest .NebulaCACert ()
696- caPEM , err := ca .MarshalToPEM ()
695+ caPEM , err := ca .MarshalPEM ()
697696 require .NoError (t , err )
698697
699698 c := NewClient (useragent , ts .URL )
@@ -720,7 +719,7 @@ func TestCommandResponse(t *testing.T) {
720719 HostID : "foobar" ,
721720 Counter : 1 ,
722721 Config : cfg ,
723- TrustedKeys : marshalCAPublicKey ( ca .Details . Curve , ca . Details . PublicKey ),
722+ TrustedKeys : ca .MarshalPublicKeyPEM ( ),
724723 Organization : message.HostOrgMetadata {
725724 ID : "foobaz" ,
726725 Name : "foobar's foo org" ,
@@ -798,7 +797,7 @@ func TestStreamCommandResponse(t *testing.T) {
798797 t .Cleanup (func () { ts .Close () })
799798
800799 ca , _ := dnapitest .NebulaCACert ()
801- caPEM , err := ca .MarshalToPEM ()
800+ caPEM , err := ca .MarshalPEM ()
802801 require .NoError (t , err )
803802
804803 c := NewClient (useragent , ts .URL )
@@ -825,7 +824,7 @@ func TestStreamCommandResponse(t *testing.T) {
825824 HostID : "foobar" ,
826825 Counter : 1 ,
827826 Config : cfg ,
828- TrustedKeys : marshalCAPublicKey ( ca .Details . Curve , ca . Details . PublicKey ),
827+ TrustedKeys : ca .MarshalPublicKeyPEM ( ),
829828 Organization : message.HostOrgMetadata {
830829 ID : "foobaz" ,
831830 Name : "foobar's foo org" ,
@@ -924,7 +923,7 @@ func TestReauthenticate(t *testing.T) {
924923 t .Cleanup (func () { ts .Close () })
925924
926925 ca , caPrivkey := dnapitest .NebulaCACert ()
927- caPEM , err := ca .MarshalToPEM ()
926+ caPEM , err := ca .MarshalPEM ()
928927 require .NoError (t , err )
929928
930929 c := NewClient (useragent , ts .URL )
@@ -951,7 +950,7 @@ func TestReauthenticate(t *testing.T) {
951950 HostID : "foobar" ,
952951 Counter : 1 ,
953952 Config : cfg ,
954- TrustedKeys : marshalCAPublicKey ( ca .Details . Curve , ca . Details . PublicKey ),
953+ TrustedKeys : ca .MarshalPublicKeyPEM ( ),
955954 Organization : message.HostOrgMetadata {
956955 ID : "foobaz" ,
957956 Name : "foobar's foo org" ,
@@ -1062,17 +1061,6 @@ func TestOverrideTimeout(t *testing.T) {
10621061 require .ErrorIs (t , err , context .DeadlineExceeded )
10631062}
10641063
1065- func marshalCAPublicKey (curve cert.Curve , pubkey []byte ) []byte {
1066- switch curve {
1067- case cert .Curve_CURVE25519 :
1068- return pem .EncodeToMemory (& pem.Block {Type : keys .NebulaEd25519PublicKeyBanner , Bytes : pubkey })
1069- case cert .Curve_P256 :
1070- return pem .EncodeToMemory (& pem.Block {Type : keys .NebulaECDSAP256PublicKeyBanner , Bytes : pubkey })
1071- default :
1072- panic ("unsupported curve" )
1073- }
1074- }
1075-
10761064func TestGetOidcPollCode (t * testing.T ) {
10771065 t .Parallel ()
10781066
@@ -1217,3 +1205,15 @@ func TestDownloads(t *testing.T) {
12171205 assert .Equal (t , "0.8.4" , resp .VersionInfo .Latest .DNClient )
12181206 assert .Equal (t , "0.5.1" , resp .VersionInfo .Latest .Mobile )
12191207}
1208+
1209+ func TestNebulaPemBanners (t * testing.T ) {
1210+ const NebulaECDSAP256PublicKeyBanner = "NEBULA ECDSA P256 PUBLIC KEY"
1211+ const NebulaEd25519PublicKeyBanner = "NEBULA ED25519 PUBLIC KEY"
1212+ ca , _ := dnapitest .NebulaCACert ()
1213+ pub := ca .MarshalPublicKeyPEM ()
1214+ assert .Contains (t , string (pub ), NebulaEd25519PublicKeyBanner )
1215+
1216+ ca , _ = dnapitest .NebulaCACertP256 ()
1217+ pub = ca .MarshalPublicKeyPEM ()
1218+ assert .Contains (t , string (pub ), NebulaECDSAP256PublicKeyBanner )
1219+ }
0 commit comments