-1

I am testing the x509 Certificate Verify example, and this (from the example) works:

const rootPEM = `
-----BEGIN CERTIFICATE-----
MIIEBDCCAuygAwIBAgIDAjppMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT
. . .
yuGnBXj8ytqU0CwIPX4WecigUCAkVDNx
-----END CERTIFICATE-----`

const certPEM = `
-----BEGIN CERTIFICATE-----
MIIDujCCAqKgAwIBAgIIE31FZVaPXTUwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE
. . .
yE+vPxsiUkvQHdO2fojCkY8jg70jxM+gu59tPDNbw3Uh/2Ij310FgTHsnGQMyA==
-----END CERTIFICATE-----`

But this does not:

const (
    rootPEM = `
    -----BEGIN CERTIFICATE-----
    MIIEBDCCAuygAwIBAgIDAjppMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT
    . . .
    yuGnBXj8ytqU0CwIPX4WecigUCAkVDNx
    -----END CERTIFICATE-----`

    certPEM = `
    -----BEGIN CERTIFICATE-----
    MIIDujCCAqKgAwIBAgIIE31FZVaPXTUwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE
    . . .
    yE+vPxsiUkvQHdO2fojCkY8jg70jxM+gu59tPDNbw3Uh/2Ij310FgTHsnGQMyA==
    -----END CERTIFICATE-----`
)

What changes when using the constant block/group? (In terms of this example, it fails at panic: failed to parse root certificate when using the constant block)

icza
  • 389,944
  • 63
  • 907
  • 827
sean
  • 3,484
  • 5
  • 27
  • 45

1 Answers1

4

"Nothing" changes, except that your grouped variant is indented, so that means all lines of the raw string literal start with tabs or spaces, which the certificate parser may take offensively.

Try it like this:

const (
    rootPEM = `
-----BEGIN CERTIFICATE-----
MIIEBDCCAuygAwIBAgIDAjppMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT
. . .
yuGnBXj8ytqU0CwIPX4WecigUCAkVDNx
-----END CERTIFICATE-----`

    certPEM = `
-----BEGIN CERTIFICATE-----
MIIDujCCAqKgAwIBAgIIE31FZVaPXTUwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE
. . .
yE+vPxsiUkvQHdO2fojCkY8jg70jxM+gu59tPDNbw3Uh/2Ij310FgTHsnGQMyA==
-----END CERTIFICATE-----`
)

(Note: multiple lines of the raw string literal are not indented.)

icza
  • 389,944
  • 63
  • 907
  • 827
  • I didn't realize raw string literals were so picky, thanks for your help! I'll mark as the answer in a few mins. – sean Nov 29 '18 at 12:37
  • 1
    It's not really "picky"--it's just doing exactly what makes sense :) – Jonathan Hall Nov 29 '18 at 12:37
  • 1
    @sean Everything in a raw string literal is taken as-is. Raw string literals are not interpreted, they are just used as appear in the source. – icza Nov 29 '18 at 12:38