글쓴이 보관물: xeozin

WKWebView 에서 사설인증서 SSL 통과하기

WKNaivagationDelegate 의 URLAuthenticationChallenge 델리게이터를 구현한다.

import UIKit
import WebKit

class ViewController: UIViewController, WKNavigationDelegate {
    @IBOutlet weak var webView: WKWebView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let url = URL(string: "https://192.168.0.26:2000")!
        webView.load(URLRequest(url: url))
        webView.navigationDelegate = self
        webView.allowsBackForwardNavigationGestures = true
        // Do any additional setup after loading the view, typically from a nib.
    }

    func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        let cred = URLCredential(trust: challenge.protectionSpace.serverTrust!)
        completionHandler(.useCredential, cred)
    }

}

 

nodejs 에서 https 사용하기

openssl을 이용해서 다음과 같이 파일을 만들수 있다.

openssl genrsa -out privatekey.pem 1024
openssl req -new -key privatekey.pem -out certrequest.csr
openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem

포트에 따라서 http 또는 https 로 이동하게 된다.

var http=require('http'),  
    https = require('https'),
    express = require('express'),
     fs = require('fs');

var options = {  
    key: fs.readFileSync('privkey.pem'),
    cert: fs.readFileSync('cert.pem')
};

var port1 = 3001;  
var port2 = 2000;

var app = express();  
app.use(express.urlencoded());

http.createServer(app).listen(port1, function(){  
  console.log("Http server listening on port " + port1);
});

https.createServer(options, app).listen(port2, function(){  
  console.log("Https server listening on port " + port2);
});

app.get('/', function (req, res) {  
    res.writeHead(200, {'Content-Type' : 'text/html'});
    res.write('<h3>Welcome</h3>');
    res.end();
});