use the new pkix.Name String() function

This commit is contained in:
Ben Toews 2018-07-16 08:26:02 -06:00
Родитель b658ac9573
Коммит ad5c511cce
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E9C423BE17EFEE70
3 изменённых файлов: 4 добавлений и 116 удалений

Просмотреть файл

@ -20,8 +20,8 @@ func commandListKeys() {
fmt.Println(" S/N:", cert.SerialNumber.Text(16))
fmt.Println("Algorithm:", cert.SignatureAlgorithm.String())
fmt.Println(" Validity:", cert.NotBefore.String(), "-", cert.NotAfter.String())
fmt.Println(" Issuer:", rdnSequenceString(cert.Issuer.ToRDNSequence()))
fmt.Println(" Subject:", rdnSequenceString(cert.Subject.ToRDNSequence()))
fmt.Println(" Issuer:", cert.Issuer.ToRDNSequence().String())
fmt.Println(" Subject:", cert.Subject.ToRDNSequence().String())
fmt.Println(" Emails:", strings.Join(certEmails(cert), ", "))
}
}

Просмотреть файл

@ -1,112 +0,0 @@
package main
import (
"crypto/x509/pkix"
"encoding/asn1"
"encoding/hex"
"fmt"
)
// The following was copied from the crypto/openpgpg/packet package.
// The original license can be found at https://git.io/vbUMQ
//
// Copyright (c) 2009 The Go Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
var attributeTypeNames = map[string]string{
"2.5.4.6": "C",
"2.5.4.10": "O",
"2.5.4.11": "OU",
"2.5.4.3": "CN",
"2.5.4.5": "SERIALNUMBER",
"2.5.4.7": "L",
"2.5.4.8": "ST",
"2.5.4.9": "STREET",
"2.5.4.17": "POSTALCODE",
"1.2.840.113549.1.9.1": "EMAIL",
}
// The orignal code can be found at https://git.io/vbUMS
//
// String implements the fmt.Stringer interface. It loosely follows the
// string conversion rules for Distinguished Names from RFC 2253.
func rdnSequenceString(r pkix.RDNSequence) string {
s := ""
for i := 0; i < len(r); i++ {
rdn := r[len(r)-1-i]
if i > 0 {
s += ", "
}
for j, tv := range rdn {
if j > 0 {
s += "+"
}
oidString := tv.Type.String()
typeName, ok := attributeTypeNames[oidString]
if !ok {
derBytes, err := asn1.Marshal(tv.Value)
if err == nil {
s += oidString + "=#" + hex.EncodeToString(derBytes)
continue // No value escaping necessary.
}
typeName = oidString
}
valueString := fmt.Sprint(tv.Value)
escaped := make([]rune, 0, len(valueString))
for k, c := range valueString {
escape := false
switch c {
case ',', '+', '"', '\\', '<', '>', ';':
escape = true
case ' ':
escape = k == 0 || k == len(valueString)-1
case '#':
escape = k == 0
}
if escape {
escaped = append(escaped, '\\', c)
} else {
escaped = append(escaped, c)
}
}
s += typeName + "=" + string(escaped)
}
}
return s
}

Просмотреть файл

@ -190,14 +190,14 @@ func emitSigCreated(cert *x509.Certificate, isDetached bool) {
}
func emitGoodSig(certs []*x509.Certificate) {
subj := rdnSequenceString(certs[0].Subject.ToRDNSequence())
subj := certs[0].Subject.ToRDNSequence().String()
fpr := certHexFingerprint(certs[0])
sGoodSig.emitf("%s %s", fpr, subj)
}
func emitBadSig(certs []*x509.Certificate) {
subj := rdnSequenceString(certs[0].Subject.ToRDNSequence())
subj := certs[0].Subject.ToRDNSequence().String
fpr := certHexFingerprint(certs[0])
sBadSig.emitf("%s %s", fpr, subj)