HTTPS/Client-authenticated: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Perl}}: Fix syntax highlighting markup) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 8: | Line 8: | ||
{{works with|C sharp|3.0}} |
{{works with|C sharp|3.0}} |
||
< |
<syntaxhighlight lang="csharp"> |
||
using System; |
using System; |
||
using System.Net; |
using System.Net; |
||
Line 32: | Line 32: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 73: | Line 73: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">using HTTP, MbedTLS |
||
conf = MbedTLS.SSLConfig(true, log_secrets="/utl/secret_key_log.log") |
conf = MbedTLS.SSLConfig(true, log_secrets="/utl/secret_key_log.log") |
||
Line 82: | Line 82: | ||
println(resp) |
println(resp) |
||
</ |
</syntaxhighlight>{{output}}<pre> |
||
HTTP.Messages.Response: |
HTTP.Messages.Response: |
||
""" |
""" |
||
Line 102: | Line 102: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
< |
<syntaxhighlight lang="scala">// version 1.2.0 |
||
import java.security.KeyStore |
import java.security.KeyStore |
||
Line 138: | Line 138: | ||
println(line) |
println(line) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
< |
<syntaxhighlight lang="lasso">local(sslcert = file('myCert.pem')) |
||
local(x = curl('https://sourceforge.net')) |
local(x = curl('https://sourceforge.net')) |
||
#x->set(CURLOPT_SSLCERT, #sslcert->readstring) |
#x->set(CURLOPT_SSLCERT, #sslcert->readstring) |
||
#sslcert->close |
#sslcert->close |
||
#x->result->asString</ |
#x->result->asString</syntaxhighlight> |
||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">a = RunThrough["curl -E myCert.pem https://www.example.com", 1] |
||
For[ i=0, i < Length[a] , i++, SomeFunction[a]]</ |
For[ i=0, i < Length[a] , i++, SomeFunction[a]]</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import httpclient, net |
||
var client = newHttpClient(sslContext = newContext(certFile = "mycert.pem")) |
var client = newHttpClient(sslContext = newContext(certFile = "mycert.pem")) |
||
var r = client.get("https://www.example.com")</ |
var r = client.get("https://www.example.com")</syntaxhighlight> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">#!/usr/bin/env perl -T |
||
use 5.018_002; |
use 5.018_002; |
||
use warnings; |
use warnings; |
||
Line 178: | Line 178: | ||
else { |
else { |
||
say $res->status_line; |
say $res->status_line; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{libheader|Phix/libcurl}} |
{{libheader|Phix/libcurl}} |
||
Exactly the same as the HTTP#Phix task, except for the CURLOPT_SSLCERT part. |
Exactly the same as the HTTP#Phix task, except for the CURLOPT_SSLCERT part. |
||
<!--< |
<!--<syntaxhighlight lang="phix">(notonline)--> |
||
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> |
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> |
||
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">libcurl</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">libcurl</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
||
Line 197: | Line 197: | ||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span> |
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang="picolisp">(in '(curl "-E" "myCert.pem" "https://www.example.com") |
||
(while (line) |
(while (line) |
||
(doSomeProcessingWithLine @) ) )</ |
(doSomeProcessingWithLine @) ) )</syntaxhighlight> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">import httplib |
||
connection = httplib.HTTPSConnection('www.example.com',cert_file='myCert.PEM') |
connection = httplib.HTTPSConnection('www.example.com',cert_file='myCert.PEM') |
||
Line 211: | Line 211: | ||
response = connection.getresponse() |
response = connection.getresponse() |
||
data = response.read() |
data = response.read() |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
Skeleton code to connect to a server: |
Skeleton code to connect to a server: |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket |
#lang racket |
||
(require openssl/mzssl) |
(require openssl/mzssl) |
||
Line 223: | Line 223: | ||
(ssl-load-verify-root-certificates! ctx "my-cert.pem") |
(ssl-load-verify-root-certificates! ctx "my-cert.pem") |
||
(define-values [I O] (ssl-connect "www.example.com" 443 ctx)) |
(define-values [I O] (ssl-connect "www.example.com" 443 ctx)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
<syntaxhighlight lang="raku" line> |
|||
<lang perl6> |
|||
# cert creation commands |
# cert creation commands |
||
Line 256: | Line 256: | ||
$s.close; |
$s.close; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">require 'uri' |
||
require 'net/http' |
require 'net/http' |
||
Line 270: | Line 270: | ||
request = Net::HTTP::Get.new uri |
request = Net::HTTP::Get.new uri |
||
http.request request |
http.request request |
||
end</ |
end</syntaxhighlight> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
{{works with|Rust|2021}} |
{{works with|Rust|2021}} |
||
Line 278: | Line 278: | ||
Native (system) TLS libraries are used instead of Rustls, the Rust TLS implementation, because we use a PKCS#12 certificate which at the time of writing does not seem to be available on Rustls. A PKCS#12 certificate is used instead of its PEM equivalent because reading password-protected PEM files [https://docs.rs/reqwest/0.11.6/reqwest/tls/struct.Identity.html#method.from_pem does not seem to be available] either. |
Native (system) TLS libraries are used instead of Rustls, the Rust TLS implementation, because we use a PKCS#12 certificate which at the time of writing does not seem to be available on Rustls. A PKCS#12 certificate is used instead of its PEM equivalent because reading password-protected PEM files [https://docs.rs/reqwest/0.11.6/reqwest/tls/struct.Identity.html#method.from_pem does not seem to be available] either. |
||
< |
<syntaxhighlight lang="toml">reqwest = {version = "0.11", features = ["native-tls", "blocking"]}</syntaxhighlight> |
||
===src/main.rs=== |
===src/main.rs=== |
||
< |
<syntaxhighlight lang="rust">use std::fs::File; |
||
use std::io::Read; |
use std::io::Read; |
||
Line 307: | Line 307: | ||
Ok(()) |
Ok(()) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
< |
<syntaxhighlight lang="scala">import java.io.FileInputStream |
||
import java.net.URL |
import java.net.URL |
||
import java.security.KeyStore |
import java.security.KeyStore |
||
Line 338: | Line 338: | ||
new BufferedSource(con.getInputStream).getLines.foreach(println(_)) |
new BufferedSource(con.getInputStream).getLines.foreach(println(_)) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
Uses the [http://tls.sourceforge.net Tls] package. |
Uses the [http://tls.sourceforge.net Tls] package. |
||
< |
<syntaxhighlight lang="tcl">package require http |
||
package require tls |
package require tls |
||
Line 357: | Line 357: | ||
# Now as for conventional use of the “http” package |
# Now as for conventional use of the “http” package |
||
set data [http::data $token] |
set data [http::data $token] |
||
http::cleanup $token</ |
http::cleanup $token</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|libcurl}} |
{{libheader|libcurl}} |
||
An embedded program so we can ask the C host to communicate with libcurl for us. |
An embedded program so we can ask the C host to communicate with libcurl for us. |
||
< |
<syntaxhighlight lang="ecmascript">/* https_client-authenticated.wren */ |
||
var CURLOPT_URL = 10002 |
var CURLOPT_URL = 10002 |
||
Line 395: | Line 395: | ||
return |
return |
||
} |
} |
||
curl.easyCleanup()</ |
curl.easyCleanup()</syntaxhighlight> |
||
<br> |
<br> |
||
We now embed this in the following C program, compile and run it. |
We now embed this in the following C program, compile and run it. |
||
< |
<syntaxhighlight lang="c">/* gcc https_client-authenticated.c -o https_client-authenticated -lcurl -lwren -lm */ |
||
#include <stdio.h> |
#include <stdio.h> |
||
Line 514: | Line 514: | ||
free(script); |
free(script); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
Uses libCurl. |
Uses libCurl. |
||
< |
<syntaxhighlight lang="zkl">var CURL=Import("zklCurl"), c=CURL(); |
||
c.setOpt("SSLCERT","certFile.pem"); c.setOpt("SSLCERTTYPE","pem"); |
c.setOpt("SSLCERT","certFile.pem"); c.setOpt("SSLCERTTYPE","pem"); |
||
c.get("http://zenkinetic.com"); // lame example to show how to read</ |
c.get("http://zenkinetic.com"); // lame example to show how to read</syntaxhighlight> |
||
{{omit from|Batch File|Does not have network access.}} |
{{omit from|Batch File|Does not have network access.}} |