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)
| 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. |
| 88 | func 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 | |
| 108 | func ParsePublicKey(text []byte) (crypto.PublicKey, error) { |
| 109 | for len(text) > 0 { |
no test coverage detected