Skip to content
Snippets Groups Projects
Unverified Commit 42aa2b04 authored by asraa's avatar asraa Committed by GitHub
Browse files

use email from SAN (#288)


Signed-off-by: default avatarAsra Ali <asraa@google.com>
parent 5d11711e
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,8 @@ import ( ...@@ -30,6 +30,8 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"strings" "strings"
"github.com/go-playground/validator"
) )
// EmailAddressOID defined by https://oidref.com/1.2.840.113549.1.9.1 // EmailAddressOID defined by https://oidref.com/1.2.840.113549.1.9.1
...@@ -176,9 +178,11 @@ func (k PublicKey) CanonicalValue() ([]byte, error) { ...@@ -176,9 +178,11 @@ func (k PublicKey) CanonicalValue() ([]byte, error) {
func (k PublicKey) EmailAddresses() []string { func (k PublicKey) EmailAddresses() []string {
var names []string var names []string
if k.cert != nil { if k.cert != nil {
for _, name := range k.cert.c.Subject.Names { for _, name := range k.cert.c.EmailAddresses {
if name.Type.Equal(EmailAddressOID) { validate := validator.New()
names = append(names, strings.ToLower(name.Value.(string))) errs := validate.Var(name, "required,email")
if errs == nil {
names = append(names, strings.ToLower(name))
} }
} }
} }
......
...@@ -47,21 +47,24 @@ baT2ax2dXBcpInWaFESqGF35KISflP1EmMvEnfG+AzHecQ0WQp5QzNId+w== ...@@ -47,21 +47,24 @@ baT2ax2dXBcpInWaFESqGF35KISflP1EmMvEnfG+AzHecQ0WQp5QzNId+w==
// Generated with: // Generated with:
// openssl req -newkey rsa:2048 -nodes -keyout test.key -x509 -out test.crt // openssl req -newkey rsa:2048 -nodes -keyout test.key -x509 -out test.crt
const rsaCert = `-----BEGIN CERTIFICATE----- const rsaCert = `-----BEGIN CERTIFICATE-----
MIICujCCAaICCQDV0chJ/QVmCTANBgkqhkiG9w0BAQsFADAfMR0wGwYJKoZIhvcN MIIDOjCCAiKgAwIBAgIUEP925shVBKERFCsymdSqESLZFyMwDQYJKoZIhvcNAQEL
AQkBFg50ZXN0QHJla29yLmRldjAeFw0yMTAyMj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HQYDVR0OBBYEFGjs8EHKT3x1itwwptJLuQQg/hQcMB8G
+z564uZlS0LyjsJjaalP/CJ9R+DO5dpRcKmBzBbMHjGSqoFW/ZIUm8Yybnd2eC7b A1UdIwQYMBaAFGjs8EHKT3x1itwwptJLuQQg/hQcMA8GA1UdEwEB/wQFMAMBAf8w
JQD+JTB4XTd4yX3Yl6qWITPYpye3zuu3oCrHoBubWyzR9EakIaEBIenYReI4jD0n GQYDVR0RBBIwEIEOdGVzdEByZWtvci5kZXYwDQYJKoZIhvcNAQELBQADggEBAAHE
40Erllt4ra2N0CkIaYei0ZfuMRkoav3jc+2OcbCzQzTDq7HIxfSirz9up6+hjn+G bYuePN3XpM7pHoCz6g4uTHu0VrezqJyK1ohysgWJmSJzzazUeISXk0xWnHPk1Zxi
GZXHemYIVbviNo9qr5cVY4OCJJQIUmGOcp+F4sNIqjbeEkTWFkeAy7sPSU8c8WQX kzoEuysI8b0P7yodMA8e16zbIOL6QbGe3lNXYqRIg+bl+4OPFGVMX8xHNZmeh0kD
l7ArJO7hmz6eJON+xDbhcYtAOavUqbT+fVcgi2qm vX1JVS+y9uyo4/z/pm0JhaSCn85ft/Y5uXMQYn1wFR5DAcJH+iWjNX4fipGxGRE9
Cy0DjFnYJ3SRY4HPQ0oUSQmyhrwe2DiYzeqtbL2KJBXPcFQKWhkf/fupdYFljvcH
d9NNfRb0p2oFGG/J0ROg9pEcP1/aZP5k8P2pRdt3y7h1MAtmg2bgEdugZgXwAUmM
BmU8k2FeTuqV15piPCE=
-----END CERTIFICATE-----` -----END CERTIFICATE-----`
const rsaKey = `-----BEGIN PRIVATE KEY----- const rsaKey = `-----BEGIN PRIVATE KEY-----
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment