MCPcopy Create free account
hub / github.com/WICG/webpackage / parseEncryptedPrivateKeyBlock

Function parseEncryptedPrivateKeyBlock

go/internal/signingalgorithm/certs.go:88–106  ·  view source on GitHub ↗

parseEncryptedPrivateKeyBlock reads the passphrase to decrypt an encrypted private key from either WEB_BUNDLE_SIGNING_PASSPHRASE environment variable or if not set, it prompts a passphrase from the user.

(derKey []byte)

Source from the content-addressed store, hash-verified

86// parseEncryptedPrivateKeyBlock reads the passphrase to decrypt an encrypted private key from either
87// WEB_BUNDLE_SIGNING_PASSPHRASE environment variable or if not set, it prompts a passphrase from the user.
88func parseEncryptedPrivateKeyBlock(derKey []byte) (crypto.PrivateKey, error) {
89 passphrase := []byte(os.Getenv("WEB_BUNDLE_SIGNING_PASSPHRASE"))
90
91 if len(passphrase) == 0 {
92 fmt.Println("The key is passphrase-encrypted. Please provide the passphrase and then press ENTER. ")
93 passphrase, _ = terminal.ReadPassword(0)
94 if len(passphrase) == 0 {
95 return nil, errors.New("signingalgorithm: invalid passphrase to decrypt the private key.")
96 }
97 } else {
98 fmt.Println("The key is passphrase-encrypted. Passphrase was successfully read from WEB_BUNDLE_SIGNING_PASSPHRASE environment variable.")
99 }
100
101 if keyInterface, err := pkcs8.ParsePKCS8PrivateKey(derKey, passphrase); err == nil {
102 return typeSupportedPKCS8key(keyInterface)
103 }
104
105 return nil, errors.New("signingalgorithm: couldn't parse encrypted private key.")
106}
107
108func ParsePublicKey(text []byte) (crypto.PublicKey, error) {
109 for len(text) > 0 {

Callers 1

ParsePrivateKeyFunction · 0.85

Calls 1

typeSupportedPKCS8keyFunction · 0.85

Tested by

no test coverage detected