Hy Natxo,

check out the pkix [0] and asn1 [1] packages. You can try to parse the
DER encoded subject into RDNSequence.

[0]: https://golang.org/pkg/crypto/x509/pkix/#RDNSequence
[1]: https://golang.org/pkg/encoding/asn1/#Unmarshal

Spoiler:

This should work:

package main

import "fmt"
import "crypto/x509"
import "encoding/asn1"
import "crypto/x509/pkix"

func main() {
  store, err := x509.SystemCertPool()
  if err != nil {
    panic(err)
  }
  subjects := store.Subjects()
  for _, rawSubject := range subjects {
    var subject pkix.RDNSequence
    if _, err := asn1.Unmarshal(rawSubject, &subject); err != nil {
      panic(err)
    }
    fmt.Printf("%+v\n", subject)
  }
}

The unmarshal code is borrowed from https://stackoverflow.com/a/50640119

Cheers,
Michael

On 31.10.18 21:04, Natxo Asenjo wrote:
> hi,
> 
> as a learning exercise I would lke to loop through the system's
> certificate authorities store, and get the subjects of each certificate
> authority.
> 
> I have this code:
> 
> package main
> 
> import "fmt"
> import "crypto/x509"
> 
> func main() {
>     store, err := x509.SystemCertPool()
>     if err != nil {
>         panic(err)
>     }
>     fmt.Printf("%T\n", store)
>     subjects := store.Subjects()
>     fmt.Printf("%T\n", subjects)
>     for _, v := range subjects {
>         fmt.Printf("%T\n", v)
>         fmt.Println(string(v))
>     }
> }
> 
> But I am getting a lot of gibberish.
> 
> There should be a better way to do this, but I obviously do not know it.
> 
> Thanks for any pointers.
> 
> -- 
> regards,
> Natxo
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to golang-nuts+unsubscr...@googlegroups.com
> <mailto:golang-nuts+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to