Flow część 2

Uwaga odnośnie cURLa

Formaty plików kluczy i certyfikatów akceptowane przez cURL zależą od biblioteki kryptograficznej, z którą cURL został skompilowany.

Poniższe przykłady udało mi się uruchomić z:

  1. curl na Ubuntu 16.04 LTS:
    1
    2
    3
    curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3
    Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp
    Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets
  2. curl na Ubuntu 18.04 LTS:
    1
    2
    3
    4
    curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.0g zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
    Release-Date: 2018-01-24
    Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp
    Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL
  3. Curl instalowanym wraz z git-bash na Windows 10 (choco install git):
    1
    2
    3
    4
    curl 7.64.0 (x86_64-w64-mingw32) libcurl/7.64.0 OpenSSL/1.1.1a (Schannel) zlib/1.2.11 libidn2/2.1.1 nghttp2/1.36.0
    Release-Date: 2019-02-06
    Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp
    Features: AsynchDNS IDN IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL libz TLS-SRP HTTP2 HTTPS-proxy MultiSSL Metalink

Nie udało mi się uruchomić poniższych przykaładów z:

  1. curl na Oracle Linux 7:
    1
    2
    3
    curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.36 zlib/1.2.7 libidn/1.28 libssh2/1.4.3
    Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
    Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets
  2. curl na Windows 10 (choco install curl):
    1
    2
    3
    4
    curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL
    Release-Date: [unreleased]
    Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp
    Features: AsynchDNS IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL

Przykład nieudanej komunikacji:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
curl -v --key ksm-kmk.rsa.pem --cert ksm-kmk.pem https://test.giif.mofnet.gov.pl/api/rest2018/instytucje/
* Trying 145.237.235.44...
* TCP_NODELAY set
* Connected to test.giif.mofnet.gov.pl (145.237.235.44) port 443 (#0)
* schannel: SSL/TLS connection with test.giif.mofnet.gov.pl port 443 (step 1/3)
* schannel: checking server certificate revocation
* schannel: sending initial handshake data: sending 188 bytes...
* schannel: sent initial handshake data: sent 188 bytes
* schannel: SSL/TLS connection with test.giif.mofnet.gov.pl port 443 (step 2/3)
* schannel: failed to receive handshake, need more data
* schannel: SSL/TLS connection with test.giif.mofnet.gov.pl port 443 (step 2/3)
* schannel: encrypted data got 3347
* schannel: encrypted data buffer: offset 3347 length 4096
* schannel: a client certificate has been requested
* schannel: SSL/TLS connection with test.giif.mofnet.gov.pl port 443 (step 2/3)
* schannel: encrypted data buffer: offset 3347 length 4371
* schannel: sending next handshake data: sending 100 bytes...
* schannel: SSL/TLS connection with test.giif.mofnet.gov.pl port 443 (step 2/3)
* schannel: encrypted data got 290
* schannel: encrypted data buffer: offset 290 length 4371
* schannel: SSL/TLS handshake complete
* schannel: SSL/TLS connection with test.giif.mofnet.gov.pl port 443 (step 3/3)
* schannel: stored credential handle in session cache
> GET /api/rest2018/instytucje/ HTTP/1.1
> Host: test.giif.mofnet.gov.pl
> User-Agent: curl/7.55.1
> Accept: */*
>
* schannel: client wants to read 102400 bytes
* schannel: encdata_buffer resized 103424
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: encrypted data got 250
* schannel: encrypted data buffer: offset 250 length 103424
* schannel: decrypted data length: 221
* schannel: decrypted data added: 221
* schannel: decrypted data cached: offset 221 length 102400
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: decrypted data buffer: offset 221 length 102400
* schannel: schannel_recv cleanup
* schannel: decrypted data returned 221
* schannel: decrypted data buffer: offset 0 length 102400
< HTTP/1.1 401 401
< Date: Fri, 05 Apr 2019 10:55:39 GMT
< Server: Apache/2.4.38 (codeit) OpenSSL/1.1.1a
< Content-Type: application/octet-stream
< Content-Length: 57
<
No authorization header provided. Can't validate the JWT.* Connection #0 to host test.giif.mofnet.gov.pl left intact

W poprzednim odcinku

W części pierwszej:

  1. Utworzyliśmy instytucję obowiązaną o NIPie 0123456789.
  2. Przesłaliśmy żądanie wystawienia certyfikatu komunikacyjnego wraz z CSRem. W trakcie tworzenia CSRa, utworzyliśmy plik ksm-kmk.prv.pem z kluczem prywatnym.
  3. Pobraliśmy certyfikat komunikacyjny i zapisaliśmy go w pliku ksm-kmk.pem.

Pobieranie listy dostępnych instytucji

Zacznijmy od pobrania listy instytucji obowiązanych, do których certyfikat komunikacyjny daje nam dostęp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
curl -v --key ksm-kmk.prv.pem --cert ksm-kmk.pem \
--output lista_instytucji.xml \
https://test.giif.mofnet.gov.pl/api/rest2018/instytucje/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 145.237.235.44...
* Connected to test.giif.mofnet.gov.pl (145.237.235.44) port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 592 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
* server certificate verification OK
* server certificate status verification SKIPPED
* common name: test.giif.mofnet.gov.pl (matched)
* server certificate expiration date OK
* server certificate activation date OK
* certificate public key: RSA
* certificate version: #3
* subject: CN=test.giif.mofnet.gov.pl
* start date: Tue, 26 Mar 2019 12:28:22 GMT
* expire date: Mon, 24 Jun 2019 12:28:22 GMT
* issuer: C=US,O=Let's Encrypt,CN=Let's Encrypt Authority X3
* compression: NULL
* ALPN, server accepted to use http/1.1
> GET /api/rest2018/instytucje/ HTTP/1.1
> Host: test.giif.mofnet.gov.pl
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 200
< Date: Fri, 05 Apr 2019 10:44:00 GMT
< Server: Apache/2.4.38 (codeit) OpenSSL/1.1.1a
< Content-Type: application/xml
< Content-Length: 1069
<
{ [1069 bytes data]
100 1069 100 1069 0 0 2628 0 --:--:-- --:--:-- --:--:-- 2633
* Connection #0 to host test.giif.mofnet.gov.pl left intact

Odpowiedź po sformatowaniu (xmllint -format lista_instytucji.xml) wygląda następująco:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:ListaInstytucji xmlns:ns2="http://crd.gov.pl/wzor/2018/10/19/5991/" xmlns:ns3="http://www.giif.mofnet.gov.pl/xsd/rest/instytucje20181218">
<Instytucja>
<ns2:Nazwa>Instytucja Przykładowa</ns2:Nazwa>
<ns2:FormaOrganizacyjna>17</ns2:FormaOrganizacyjna>
<ns2:NIP>0123456789</ns2:NIP>
<ns2:Adres>
<ns2:Kraj>PL</ns2:Kraj>
<ns2:Miejscowosc>Warszawa</ns2:Miejscowosc>
<ns2:Kod>00-916</ns2:Kod>
<ns2:Gmina>04241</ns2:Gmina>
<ns2:Ulica>Świętokrzyska</ns2:Ulica>
<ns2:NumerDomu>12</ns2:NumerDomu>
</ns2:Adres>
<ns2:RodzajInstytucji>451</ns2:RodzajInstytucji>
</Instytucja>
<Instytucja>
<ns2:Nazwa>TESTOWY_1</ns2:Nazwa>
<ns2:FormaOrganizacyjna>00</ns2:FormaOrganizacyjna>
<ns2:NIP>6770065406</ns2:NIP>
<ns2:Adres>
<ns2:Kraj>PL</ns2:Kraj>
<ns2:Miejscowosc>Testowo</ns2:Miejscowosc>
<ns2:Kod>01-777</ns2:Kod>
<ns2:Gmina>03040</ns2:Gmina>
<ns2:Ulica>Testowa</ns2:Ulica>
<ns2:NumerDomu>1</ns2:NumerDomu>
<ns2:NrLokalu/>
</ns2:Adres>
<ns2:RodzajInstytucji>0</ns2:RodzajInstytucji>
</Instytucja>
</ns3:ListaInstytucji>

Istotną informacją są NIPy instytucji, konieczne do tworzenia żądań wysyłania plików i pobierania UPO.

Pobieranie danych instytucji

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
curl -v --key ksm-kmk.rsa.pem --cert ksm-kmk.pem \
--output 0123456789.xml \
https://test.giif.mofnet.gov.pl/api/rest2018/instytucje/0123456789/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 145.237.235.44...
* TCP_NODELAY set
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to test.giif.mofnet.gov.pl (145.237.235.44) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
} [5 bytes data]
* (304) (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* (304) (IN), TLS handshake, Server hello (2):
{ [80 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [2573 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [300 bytes data]
* TLSv1.2 (IN), TLS handshake, Request CERT (13):
{ [375 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Certificate (11):
} [1185 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [37 bytes data]
* TLSv1.2 (OUT), TLS handshake, CERT verify (15):
} [264 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: CN=test.giif.mofnet.gov.pl
* start date: Jun 17 08:54:50 2019 GMT
* expire date: Sep 15 08:54:50 2019 GMT
* subjectAltName: host "test.giif.mofnet.gov.pl" matched cert's "test.giif.mofnet.gov.pl"
* issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
* SSL certificate verify ok.
} [5 bytes data]
> GET /api/rest2018/instytucje/0123456789/ HTTP/1.1
> Host: test.giif.mofnet.gov.pl
> User-Agent: curl/7.58.0
> Accept: */*
>
{ [5 bytes data]
< HTTP/1.1 200 200
< Date: Thu, 25 Jul 2019 09:35:19 GMT
< Server: Apache
< Content-Type: application/xml
< Content-Length: 1571
<
{ [1571 bytes data]
100 1571 100 1571 0 0 6600 0 --:--:-- --:--:-- --:--:-- 6573
* Connection #0 to host test.giif.mofnet.gov.pl left intact

Odpowiedź po sformatowaniu:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns6:Dokument xmlns="http://crd.gov.pl/xml/schematy/struktura/2009/11/16/" xmlns:ns2="http://crd.gov.pl/xml/schematy/meta/2009/11/16/" xmlns:ns3="http://crd.gov.pl/xml/schematy/instytucja/2009/11/16/" xmlns:ns4="http://crd.gov.pl/xml/schematy/adres/2009/11/09/" xmlns:ns5="http://crd.gov.pl/xml/schematy/osoba/2009/11/16/" xmlns:ns6="http://crd.gov.pl/wzor/2018/10/19/5991/" xmlns:ns7="http://crd.gov.pl/wzor/2018/10/19/5992/" xmlns:ns8="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2018/10/10/giif/typy/" xmlns:ns9="http://crd.gov.pl/wzor/2018/10/19/5993/" xmlns:ns10="http://crd.gov.pl/wzor/2018/10/19/5995/" xmlns:ns11="http://crd.gov.pl/wzor/2018/10/30/6031/" xmlns:ns12="http://www.giif.mofnet.gov.pl/xsd/transakcje/2019/01/11/celnicy">
<ns6:OpisDokumentu/>
<ns6:DaneDokumentu/>
<ns6:TrescDokumentu rodzaj="inny" format="application/xml" kodowanie="XML">
<ns6:Karta aktualizacja="true">
<ns6:Nazwa>Instytucja testowa</ns6:Nazwa>
<ns6:FormaOrganizacyjna>17</ns6:FormaOrganizacyjna>
<ns6:NIP>0123456789</ns6:NIP>
<ns6:Adres>
<ns6:Kraj>PL</ns6:Kraj>
<ns6:Miejscowosc>Warszawa</ns6:Miejscowosc>
<ns6:Kod>00-001</ns6:Kod>
<ns6:Gmina>03285</ns6:Gmina>
<ns6:Ulica>Testowa</ns6:Ulica>
<ns6:NumerDomu>15</ns6:NumerDomu>
</ns6:Adres>
<ns6:OsobaOdpowiedzialna>
<ns6:ImiePierwsze>Tester</ns6:ImiePierwsze>
<ns6:Nazwisko>Testowy</ns6:Nazwisko>
<ns6:Telefon>123456785</ns6:Telefon>
<ns6:Email>test@example.com</ns6:Email>
</ns6:OsobaOdpowiedzialna>
<ns6:RodzajInstytucji>451</ns6:RodzajInstytucji>
</ns6:Karta>
</ns6:TrescDokumentu>
</ns6:Dokument>