第27月第27天 https
1.验证签名
{
[self generateRSAKeyPair:kRSA_KEY_SIZE];
NSData *ttDt = [@"" dataUsingEncoding:NSASCIIStringEncoding];
NSData *sha1dg = [ttDt hashDataWith:CCDIGEST_SHA1];
OSStatus ret;
//私钥签名,公钥验证签名
size_t siglen = SecKeyGetBlockSize(privateKeyRef);
uint8_t *sig = malloc(siglen);
bzero(sig, siglen);
ret = SecKeyRawSign(privateKeyRef, kSecPaddingPKCS1SHA256, sha1dg.bytes, sha1dg.length, sig, &siglen);
NSAssert(ret==errSecSuccess, @"签名失败");
ret = SecKeyRawVerify(publicKeyRef, kSecPaddingPKCS1SHA256, sha1dg.bytes, sha1dg.length,sig, siglen);
NSAssert(ret==errSecSuccess, @"验证签名失败");
if (ret==errSecSuccess) {
NSLog(@"SIGN VERIFY PASS");
}
}
-----------------------------------------------------
1.

https://blog.csdn.net/laughing2333/article/details/52292481
14.这么多机器,第三方机构的公钥怎么跑到了客户端的机器中呢?
其实呢,现实中,浏览器和操作系统都会维护一个权威的第三方机构列表(包括它们的公钥)。因为客户端接收到的证书中会写有颁发机构,客户端就根据这个颁发机构的值在本地找相应的公钥。
https://www.cnblogs.com/ghjbk/p/6738069.html
openssl 给自己颁发证书的步骤:
前提:先建一个cert目录,cd到该目录,以下所有命令的当前路径均为该目录
1. 生成私钥KEY
|
1
|
openssl genrsa -des3 -out server.key 2048 |
这一步执行完以后,cert目录下会生成server.key文件
2. 生成证书请求文件CSR
|
1
|
openssl req -new -key server.key -out server.csr |
该命令先进入交互模式,让你填一堆东西,参考下图:

要注意的是Common Name这里,要填写成使用SSL证书(即:https协议)的域名或主机名,否则浏览器会认为不安全。例如:如果以后打算用https://yjm-docker/xxx 这里就填写yjm-docker
3. 生成CA的证书
前面提过X.509证书的认证者总是CA或由CA指定的人,所以得先生成一个CA的证书
|
1
|
openssl req -new -x509 -key server.key -out ca.crt -days 3650 |
4. 最后用第3步的CA证书给自己颁发一个证书玩玩
|
1
2
3
|
openssl x509 -req -days 3650 -in server.csr \ -CA ca.crt -CAkey server.key \ -CAcreateserial -out server.crt |
执行完以后,cert目录下server.crt 就是我们需要的证书。当然,如果要在google等浏览器显示出安全的绿锁标志,自己颁发的证书肯定不好使,得花钱向第三方权威证书颁发机构申请(即:第4步是交给权威机构来做,我们只需要提交server.key、server.csr,哦,还有毛爷爷就好了)
http://www.cnblogs.com/lan1x/p/5872915.html
2.
unsigned char* bufferArray=new unsigned char[Len];
int result=fread(bufferArray, , Len, file);
cout << result << endl; unsigned char* p;
p = bufferArray;
X509* pX509 = NULL;
d2i_X509(&pX509, (unsigned char const **)&p, Len);
if (pX509 == NULL)
{
cout << "error" << endl;
return ;
}
else {
printX509(pX509);
}
https://www.jianshu.com/p/d049555ce0c7
https://www.cnblogs.com/blfshiye/p/5074965.html
http://blog.chinaunix.net/uid-20054105-id-1979636.html?utm_source=jiancool
https://github.com/certificate-helper/TLS-Inspector
https://www.jianshu.com/p/3e019981c118
3.
SSL
SSL是基于非对称加密的原理,在这之上还进行了对称加密的数据传输。当传送数据量过大的时候,客户端和服务器之间互相商定了一个对话密钥(session key),使用这个对话密钥来进行对称加密加快运算速度。
整个SSL的流程如下:
客户端向服务器请求证书,验证无误后拿到服务器的公钥
双方协商生成一个session key
最后双方采用session key进行加密通信
主要关注前两步,即SSL的握手阶段。
Client Hello
客户端向服务器发出一个随机数,以及支持的传输协议以及加密算法 ,压缩方法。
Server Hello
服务器在确认支持客户端的传输协议等要求后,发送服务器的证书,以及一个随机数,安全需求更高的服务器会要求客户端发送证书来证明客户端的身份。
客户端回应
客户端此时生成第三个随机数(这一个随机数被称为pre-master-key),向CA验证服务器的证书以后拿到服务器的公钥,使用公钥加密第三个随机数,并把加密后的第三个随机数发送给服务器。
客户端在本地利用之前与服务器商量好的加密方法,根据这三个随机数生成一个对话密钥(session key)用于两端通信。
服务端回应
服务端收到第三个随机数后,计算出对话密钥,至此,握手阶段结束。接下来使用对话密钥进行通信即可。
https://blog.csdn.net/laughing2333/article/details/52292481
4.
# 验证server证书
openssl verify -CAfile ca.crt server.crt
https://github.com/Ztiany/Programming-Notes/blob/ed0f19d9f776d8eaf49e8c5d243dc35e2f8a9894/Network/ProtocolBasic/HTTPS%E6%9D%83%E5%A8%81%E6%8C%87%E5%8D%97-OpenSSL%26Keytool.md
http://blog.51cto.com/ipcpu/1982109
https://www.cnblogs.com/274914765qq/p/4673327.html
5.
https://www.jianshu.com/p/d049555ce0c7
SecTrustSetAnchorCertificates
NSMutableArray *pinnedCertificates = [NSMutableArray array];
for (NSData *certificateData in self.pinnedCertificates) {
[pinnedCertificates addObject:(__bridge_transfer id)SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificateData)];
} NSString *cerFile = [[NSBundle mainBundle] pathForResource:@"anychat.net.cn.cer" ofType:nil]; OSStatus err;
NSData * certData;
SecCertificateRef cert;
SecPolicyRef policy;
SecTrustRef serverTrust;
SecTrustResultType trustResult;
SecKeyRef publicKeyRef; certData = [NSData dataWithContentsOfFile:cerFile];
cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef) certData);
policy = SecPolicyCreateBasicX509();
err = SecTrustCreateWithCertificates(cert, policy, &serverTrust);
NSAssert(err==errSecSuccess,@"证书加载失败"); SecTrustSetAnchorCertificates(serverTrust, (__bridge CFArrayRef)pinnedCertificates); if (!AAFServerTrustIsValid(serverTrust)) { } // obtain the chain after being validated, which *should* contain the pinned certificate in the last position (if it's the Root CA)
NSArray *serverCertificates = AAFCertificateTrustChainForServerTrust(serverTrust); for (NSData *trustChainCertificate in [serverCertificates reverseObjectEnumerator]) {
if ([self.pinnedCertificates containsObject:trustChainCertificate]) {
}
}
http://ios.jobbole.com/89070/
https://www.jianshu.com/p/31bcddf44b8d
8.
source 'https://github.com/CocoaPods/Specs.git'
target 'boringssl01' do
platform :ios, '9.0'
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'Firebase/Database'
pod 'Firebase/Firestore'
end
9.
In order to fulfill its purpose of verifying the identity of its owner, a certificate contains such information as:
The certificate issuer
The certificate holder
A validity period (the certificate isn’t valid before or after this period)
The public key of the certificate’s owner
Certificate extensions, which contain additional information such as alternative names for the certificate holder and allowable uses for the private key associated with the certificate
A digital signature from the certification authority to ensure that the certificate hasn’t been altered and to indicate the identity of the issuer
The certificate, key, and trust services API provides functions to examine the properties of a certificate. For example, the SecCertificateCopySubjectSummary function returns a human readable summary of the certificate:
https://developer.apple.com/documentation/security/certificate_key_and_trust_services/certificates/examining_a_certificate?language=objc
第27月第27天 https的更多相关文章
- Adobe Flash Player 27 on Fedora 27/26, CentOS/RHEL 7.4/6.9
This is guide, howto install Adobe Flash Player Plugin version 27 (32-bit and 64-bit) with YUM/DNF o ...
- JAVA 基础编程练习题27 【程序 27 求素数】
27 [程序 27 求素数] 题目:求 100 之内的素数 package cskaoyan; public class cskaoyan27 { @org.junit.Test public voi ...
- 第29月第27天 Error: Multiple commands produce
1. 解决方法可以有两种,一种是不使用New Build System,在File > Project/Workspace Settings中的Share Project/Workspace S ...
- 第27月第28天 iOS bundle
1. 7.如果将自己打包的bundle给别人使用,别人在打包上传过程中可能会遇到错误提示如: ERROR ITMS-90171: "Invalid Bundle Structure - Th ...
- 第27月第25天 clang -rewrite-objc main.m
1.clang -rewrite-objc main.m #import <objc/runtime.h> #import<objc/message.h> #import &l ...
- 第27月第24天 git pull fetch
1. 在进行 pull 操作的同时,其实就是 fetch+merge 的一个过程.我们从 remote 分支中拉取新的更新,然后再合并到本地分支中去. 如果 remote 分支超前于本地分支,并且本地 ...
- 第27月第18天 epoll lt et
1. While the usage of epoll when employed as a level-triggered interface does have the same semantic ...
- 第27月第17天 objc_msgSendSuper
1.objc_msgSendSuper super 的含义,消息转发会调用 objc_msgSendSuper, 就是 去父类的方法列表中找到 initWithFrame:这个方法,然后调用,调用的主 ...
- 第27月第12天 webrtc ios openssl boost
1. source 'https://github.com/CocoaPods/Specs.git' target 'YOUR_APPLICATION_TARGET_NAME_HERE' do pla ...
随机推荐
- OpenLayers学习笔记(五)— 拖拽Feature图层
参考文档的例子可以知道如何拖动矢量图层feature GitHub: 八至 作者:狐狸家的鱼 本文链接:拖拽Feature图层 全部代码 <!DOCTYPE html> <html& ...
- Python经典算法片段
将一个正整数分解质因数 #!/bin/env python2 # -*- coding: UTF-8 -*- def reduceNum(n): print '{} = '.format(n), if ...
- A1121. Damn Single
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...
- linux:逐行合并两文件(paste命令)
存在file1.txt 1 2 3 4 5 6 file2.txt a b c d e f 现希望生成file3.txt 1 2 a b 3 4 c d 5 6 e f 则可以用到如下命令: past ...
- 苹果电脑利用curl下载数据集
在看tensorflow书上迁徙学习的这一部分的时候,书上说利用 curl http://download.tensorflow.org/example_images/flower_photos.tg ...
- 转:upload.parseRequest为空
上传是items一直是空list.导致原因是struts2把原始的原来S2为简化上传功能,把所有的enctype="multipart/form-data"表单做了wrapper最 ...
- YII 框架在windows系统下的安装
第一步,下载yiii框架 http://www.yiichina.com 第二步安装: 1.首先需要下载应用模板,分为基础模板和高级应用模板,这里我以高级应用模板为例子 : 去这里现在高级应用模板 h ...
- (LIS DP) codeVs 1044 拦截导弹
题目描述 Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度.某 ...
- python自动化开发-[第七天]-面向对象
今日概要: 1.继承 2.封装 3.多态与多态性 4.反射 5.绑定方法和非绑定方法 一.新式类和经典类的区别 大前提: 1.只有在python2中才分新式类和经典类,python3中统一都是新式类 ...
- python对象继承
继承允许我们在两个或者更多的类之间创建一种“是一个”的关系,这种关系把共同的细节抽象到一个超类里. 从技术上讲,每一个我们创建的类都使用了继承,所有的python类都是一个叫做object的特殊类的子 ...