Re: [go-nuts] [crypto/x509] SystemCertPool() print subjects of ca certs

2018-10-31 Thread Natxo Asenjo


On Wednesday, October 31, 2018 at 10:46:41 PM UTC+1, golan...@geek1.de 
wrote:
>
> 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, ); err != nil { 
>   panic(err) 
> } 
> fmt.Printf("%+v\n", subject) 
>   } 
> } 
>
> The unmarshal code is borrowed from https://stackoverflow.com/a/50640119 
>
> Cheers, 
> Michael 
>
>  
Hi,

it works beautifully. Thanks a lot.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] [crypto/x509] SystemCertPool() print subjects of ca certs

2018-10-31 Thread golang-nuts via golang-nuts
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, ); 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
> .
> 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.


[go-nuts] [crypto/x509] SystemCertPool() print subjects of ca certs

2018-10-31 Thread Natxo Asenjo
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.
For more options, visit https://groups.google.com/d/optout.