Explorar el Código

avoid manipulating the key PEM format and take a plain PEM key as input

beltram hace 3 años
padre
commit
ca01c74333
Se han modificado 1 ficheros con 13 adiciones y 7 borrados
  1. 13 7
      acme/challenge.go

+ 13 - 7
acme/challenge.go

@@ -1,6 +1,7 @@
 package acme
 package acme
 
 
 import (
 import (
+	"bytes"
 	"context"
 	"context"
 	"crypto"
 	"crypto"
 	"crypto/ecdsa"
 	"crypto/ecdsa"
@@ -15,7 +16,6 @@ import (
 	"encoding/base64"
 	"encoding/base64"
 	"encoding/hex"
 	"encoding/hex"
 	"encoding/json"
 	"encoding/json"
-	"encoding/pem"
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
@@ -429,7 +429,8 @@ func wireDPOP01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose.JSO
 		return NewErrorISE("missing provisioner")
 		return NewErrorISE("missing provisioner")
 	}
 	}
 
 
-	key := ed25519.PublicKey([]byte(provisioner.GetOptions().GetDPOPOptions().GetSigningKey()))
+	//key := ed25519.PublicKey([]byte(provisioner.GetOptions().GetDPOPOptions().GetSigningKey()))
+	key := provisioner.GetOptions().GetDPOPOptions().GetSigningKey()
 
 
 	var wireChallengePayload WireChallengePayload
 	var wireChallengePayload WireChallengePayload
 	err := json.Unmarshal(payload, &wireChallengePayload)
 	err := json.Unmarshal(payload, &wireChallengePayload)
@@ -447,12 +448,17 @@ func wireDPOP01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose.JSO
 	defer file.Close()
 	defer file.Close()
 	defer os.Remove(file.Name())
 	defer os.Remove(file.Name())
 
 
-	err = pem.Encode(file, &pem.Block{
-		Type:  "PUBLIC KEY",
-		Bytes: key,
-	})
+	log.Printf("key: %s", key)
+
+	buf := bytes.NewBuffer(nil)
+	buf.WriteString(key)
+
+	n, err := file.Write(buf.Bytes())
 	if err != nil {
 	if err != nil {
-		return NewErrorISE("could not PEM-encode public key")
+		log.Print("writing to key file:", err)
+	}
+	if n != buf.Len() {
+		log.Printf("expected to write %d characters to the key file, got %d", buf.Len(), n)
 	}
 	}
 
 
 	challengeValues, err := wire.ParseID([]byte(ch.Value))
 	challengeValues, err := wire.ParseID([]byte(ch.Value))