验证 HTTPS 请求的证书(五)

ESP32 HTTPS客户端POST请求(跳过证书验证) ESP32 HTTPS客户端POST请求 阅读详情


Blog: [Draveness](http://draveness.me)


<iframe src="http://ghbtns.com/github-btn.html?user=draveness&type=follow&size=large" height="30" width="240" frameborder="0" scrolling="0" style="width:240px; height: 30px;" allowTransparency="true"></iframe>


自 iOS9 发布之后,由于新特性 [App Transport Security](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html) 的引入,在默认行为下是不能发送 HTTP 请求的。很多网站都在转用 HTTPS,而 `AFNetworking` 中的 `AFSecurityPolicy` 就是为了阻止中间人攻击,以及其它漏洞的工具。


`AFSecurityPolicy` 主要作用就是验证 HTTPS 请求的证书是否有效,如果 app 中有一些敏感信息或者涉及交易信息,一定要使用 HTTPS 来保证交易或者用户信息的安全。


## AFSSLPinningMode


使用 `AFSecurityPolicy` 时,总共有三种验证服务器是否被信任的方式:


```objectivec

typedef NS_ENUM(NSUInteger, AFSSLPinningMode) {

    AFSSLPinningModeNone,

    AFSSLPinningModePublicKey,

    AFSSLPinningModeCertificate,

};

```


+ `AFSSLPinningModeNone` 是默认的认证方式,只会在系统的信任的证书列表中对服务端返回的证书进行验证

+ `AFSSLPinningModeCertificate` 需要客户端预先保存服务端的证书

+ `AFSSLPinningModePublicKey` 也需要预先保存服务端发送的证书,但是这里只会验证证书中的公钥是否正确


## 初始化以及设置


在使用 `AFSecurityPolicy` 验证服务端是否受到信任之前,要对其进行初始化,使用初始化方法时,主要目的是设置**验证服务器是否受信任的方式**。


```objectivec

+ (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode {

    return [self policyWithPinningMode:pinningMode withPinnedCertificates:[self defaultPinnedCertificates]];

}


+ (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode withPinnedCertificates:(NSSet *)pinnedCertificates {

    AFSecurityPolicy *securityPolicy = [[self alloc] init];

    securityPolicy.SSLPinningMode = pinningMode;


    [securityPolicy setPinnedCertificates:pinnedCertificates];


    return securityPolicy;

}

```


这里没有什么地方值得解释的。不过在调用 `pinnedCertificate` 的 setter 方法时,会从全部的证书中**取出公钥**保存到 `pinnedPublicKeys` 属性中。


```objectivec

- (void)setPinnedCertificates:(NSSet *)pinnedCertificates {

    _pinnedCertificates = pinnedCertificates;


    if (self.pinnedCertificates) {

        NSMutableSet *mutablePinnedPublicKeys = [NSMutableSet setWithCapacity:[self.pinnedCertificates count]];

        for (NSData *certificate in self.pinnedCertificates) {

            id publicKey = AFPublicKeyForCertificate(certificate);

            if (!publicKey) {

                continue;

            }

            [mutablePinnedPublicKeys addObject:publicKey];

        }

        self.pinnedPublicKeys = [NSSet setWithSet:mutablePinnedPublicKeys];

    } else {

        self.pinnedPublicKeys = nil;

    }

}

```


在这里调用了 `AFPublicKeyForCertificate` 对证书进行操作,返回一个公钥。


## 操作 SecTrustRef


对 `serverTrust` 的操作的函数基本上都是 C 的 API,都定义在 `Security` 模块中,先来分析一下在上一节中 `AFPublicKeyForCertificate` 的实现


```objectivec

static id AFPublicKeyForCertificate(NSData *certificate) {

    id allowedPublicKey = nil;

    SecCertificateRef allowedCertificate;

    SecCertificateRef allowedCertificates[1];

    CFArrayRef tempCertificates = nil;

    SecPolicyRef policy = nil;

    SecTrustRef allowedTrust = nil;

    SecTrustResultType result;


    allowedCertificate = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificate);

    __Require_Quiet(allowedCertificate != NULL, _out);


    allowedCertificates[0] = allowedCertificate;

    tempCertificates = CFArrayCreate(NULL, (const void **)allowedCertificates, 1, NULL);


    policy = SecPolicyCreateBasicX509();

    __Require_noErr_Quiet(SecTrustCreateWithCertificates(tempCertificates, policy, &allowedTrust), _out);

    __Require_noErr_Quiet(SecTrustEvaluate(allowedTrust, &result), _out);


    allowedPublicKey = (__bridge_transfer id)SecTrustCopyPublicKey(allowedTrust);


_out:

    if (allowedTrust) {

        CFRelease(allowedTrust);

    }


    if (policy) {

        CFRelease(policy);

    }


    if (tempCertificates) {

        CFRelease(tempCertificates);

    }


    if (allowedCertificate) {

        CFRelease(allowedCertificate);

    }


    return allowedPublicKey;

}

```


1. 初始化一坨临时变量


```objectivec

id allowedPublicKey = nil;

SecCertificateRef allowedCertificate;

SecCertificateRef allowedCertificates[1];

CFArrayRef tempCertificates = nil;

SecPolicyRef policy = nil;

SecTrustRef allowedTrust = nil;

SecTrustResultType result;

```


2. 使用 `SecCertificateCreateWithData` 通过 DER 表示的数据生成一个 `SecCertificateRef`,然后判断返回值是否为 `NULL`


```objectivec

allowedCertificate = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificate);

__Require_Quiet(allowedCertificate != NULL, _out);

```

+ 这里使用了一个非常神奇的宏 `__Require_Quiet`,它会判断 `allowedCertificate != NULL` 是否成立,如果 `allowedCertificate` 为空就会跳到 `_out` 标签处继续执行


```objectivec

#ifndef __Require_Quiet

#define __Require_Quiet(assertion, exceptionLabel)                            \

  do                                                                          \

  {                                                                           \

  if ( __builtin_expect(!(assertion), 0) )                                \

  {                                                                       \

  goto exceptionLabel;                                                \

  }                                                                       \

  } while ( 0 )

#endif

```


3. 通过上面的 `allowedCertificate` 创建一个 `CFArray`


```objectivec

allowedCertificates[0] = allowedCertificate;

tempCertificates = CFArrayCreate(NULL, (const void **)allowedCertificates, 1, NULL);

```

+ 下面的 `SecTrustCreateWithCertificates` 只会接收数组作为参数。

4. 创建一个默认的符合 X509 标准的 `SecPolicyRef`,通过默认的 `SecPolicyRef` 和证书创建一个 `SecTrustRef` 用于信任评估,对该对象进行信任评估,确认生成的 `SecTrustRef` 是值得信任的。


```objectivec

    policy = SecPolicyCreateBasicX509();

    __Require_noErr_Quiet(SecTrustCreateWithCertificates(tempCertificates, policy, &allowedTrust), _out);

    __Require_noErr_Quiet(SecTrustEvaluate(allowedTrust, &result), _out);

```

+ 这里使用的 `__Require_noErr_Quiet` 和上面的宏差不多,只是会根据返回值判断是否存在错误。

5. 获取公钥


```objectivec

allowedPublicKey = (__bridge_transfer id)SecTrustCopyPublicKey(allowedTrust);

```


+ 这里的 `__bridge_transfer` 会将结果桥接成 `NSObject` 对象,然后将 `SecTrustCopyPublicKey` 返回的指针释放。

6. 释放各种 C 语言指针


```objectivec

if (allowedTrust) {

    CFRelease(allowedTrust);

}

if (policy) {

    CFRelease(policy);

}

if (tempCertificates) {

    CFRelease(tempCertificates);

}

if (allowedCertificate) {

    CFRelease(allowedCertificate);

}

```

> 每一个 `SecTrustRef` 的对象都是包含多个 `SecCertificateRef` 和 `SecPolicyRef`。其中 `SecCertificateRef` 可以使用 DER 进行表示,并且其中存储着公钥信息。


对它的操作还有 `AFCertificateTrustChainForServerTrust` 和 `AFPublicKeyTrustChainForServerTrust` 但是它们几乎调用了相同的 API。


```objectivec

static NSArray * AFCertificateTrustChainForServerTrust(SecTrustRef serverTrust) {

    CFIndex certificateCount = SecTrustGetCertificateCount(serverTrust);

    NSMutableArray *trustChain = [NSMutableArray arrayWithCapacity:(NSUInteger)certificateCount];


    for (CFIndex i = 0; i < certificateCount; i++) {

        SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, i);

        [trustChain addObject:(__bridge_transfer NSData *)SecCertificateCopyData(certificate)];

    }


    return [NSArray arrayWithArray:trustChain];

}

```


+ `SecTrustGetCertificateAtIndex` 获取 `SecTrustRef` 中的证书

+ `SecCertificateCopyData` 从证书中或者 DER 表示的数据


## 验证服务端是否受信


验证服务端是否守信是通过 `- [AFSecurityPolicy evaluateServerTrust:forDomain:]` 方法进行的。


```objectivec

- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust

                  forDomain:(NSString *)domain

{


#1: 不能隐式地信任自己签发的证书

#2: 设置 policy

#3: 验证证书是否有效

#4: 根据 SSLPinningMode 对服务端进行验证

    

    return NO;

}

```


1. 不能隐式地信任自己签发的证书


```objectivec

if (domain && self.allowInvalidCertificates && self.validatesDomainName && (self.SSLPinningMode == AFSSLPinningModeNone || [self.pinnedCertificates count] == 0)) {

    NSLog(@"In order to validate a domain name for self signed certificates, you MUST use pinning.");

    return NO;

}

```


> Do not implicitly trust self-signed certificates as anchors (kSecTrustOptionImplicitAnchors).

> Instead, add your own (self-signed) CA certificate to the list of trusted anchors.


+ 所以如果没有提供证书或者不验证证书,并且还设置 `allowInvalidCertificates` 为**真**,满足上面的所有条件,说明这次的验证是不安全的,会直接返回 `NO`

2. 设置 policy


```objectivec

NSMutableArray *policies = [NSMutableArray array];

if (self.validatesDomainName) {

    [policies addObject:(__bridge_transfer id)SecPolicyCreateSSL(true, (__bridge CFStringRef)domain)];

} else {

    [policies addObject:(__bridge_transfer id)SecPolicyCreateBasicX509()];

}

```


+ 如果要验证域名的话,就以域名为参数创建一个 `SecPolicyRef`,否则会创建一个符合 X509 标准的默认 `SecPolicyRef` 对象

3. 验证证书的有效性


```objectivec

if (self.SSLPinningMode == AFSSLPinningModeNone) {

    return self.allowInvalidCertificates || AFServerTrustIsValid(serverTrust);

} else if (!AFServerTrustIsValid(serverTrust) && !self.allowInvalidCertificates) {

    return NO;

}

```


+ 如果**只根据信任列表中的证书**进行验证,即 `self.SSLPinningMode == AFSSLPinningModeNone`。如果允许无效的证书的就会直接返回 `YES`。不允许就会对服务端信任进行验证。

+ 如果服务器信任无效,并且不允许无效证书,就会返回 `NO`

4. 根据 `SSLPinningMode` 对服务器信任进行验证


```objectivec

switch (self.SSLPinningMode) {

    case AFSSLPinningModeNone:

    default:

        return NO;

    case AFSSLPinningModeCertificate: {

...

    }

    case AFSSLPinningModePublicKey: {

...

    }

}

```


+ `AFSSLPinningModeNone` 直接返回 `NO`

+ `AFSSLPinningModeCertificate`


```objectivec

NSMutableArray *pinnedCertificates = [NSMutableArray array];

for (NSData *certificateData in self.pinnedCertificates) {

    [pinnedCertificates addObject:(__bridge_transfer id)SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificateData)];

}

SecTrustSetAnchorCertificates(serverTrust, (__bridge CFArrayRef)pinnedCertificates);

if (!AFServerTrustIsValid(serverTrust)) {

    return NO;

}

// obtain the chain after being validated, which *should* contain the pinned certificate in the last position (if it's the Root CA)

NSArray *serverCertificates = AFCertificateTrustChainForServerTrust(serverTrust);

for (NSData *trustChainCertificate in [serverCertificates reverseObjectEnumerator]) {

    if ([self.pinnedCertificates containsObject:trustChainCertificate]) {

        return YES;

    }

}

return NO;

```

1. 从 `self.pinnedCertificates` 中获取 DER 表示的数据

2. 使用 `SecTrustSetAnchorCertificates` 为服务器信任设置证书

3. 判断服务器信任的有效性

4. 使用 `AFCertificateTrustChainForServerTrust` 获取服务器信任中的全部 DER 表示的证书

5. 如果 `pinnedCertificates` 中有相同的证书,就会返回 `YES`


+ `AFSSLPinningModePublicKey`


```objectivec

NSUInteger trustedPublicKeyCount = 0;

NSArray *publicKeys = AFPublicKeyTrustChainForServerTrust(serverTrust);

for (id trustChainPublicKey in publicKeys) {

    for (id pinnedPublicKey in self.pinnedPublicKeys) {

        if (AFSecKeyIsEqualToKey((__bridge SecKeyRef)trustChainPublicKey, (__bridge SecKeyRef)pinnedPublicKey)) {

            trustedPublicKeyCount += 1;

        }

    }

}

return trustedPublicKeyCount > 0;

```


+ 这部分的实现和上面的差不多,区别有两点

1. 会从服务器信任中获取公钥

2. `pinnedPublicKeys` 中的公钥与服务器信任中的公钥相同的数量大于 0,就会返回真


## 与 AFURLSessionManager 协作


在代理协议 `- URLSession:didReceiveChallenge:completionHandler:` 或者 `- URLSession:task:didReceiveChallenge:completionHandler:` 代理方法被调用时会运行这段代码


```objectivec

if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {

    if ([self.securityPolicy evaluateServerTrust:challenge.protectionSpace.serverTrust forDomain:challenge.protectionSpace.host]) {

        disposition = NSURLSessionAuthChallengeUseCredential;

        credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];

    } else {

        disposition = NSURLSessionAuthChallengeRejectProtectionSpace;

    }

} else {

    disposition = NSURLSessionAuthChallengePerformDefaultHandling;

}

```


`NSURLAuthenticationChallenge` 表示一个认证的挑战,提供了关于这次认证的全部信息。它有一个非常重要的属性 `protectionSpace`,这里保存了需要认证的保护空间, 每一个 `NSURLProtectionSpace` 对象都保存了主机地址,端口和认证方法等重要信息。


在上面的方法中,如果保护空间中的认证方法为 `NSURLAuthenticationMethodServerTrust`,那么就会使用在上一小节中提到的方法 `- [AFSecurityPolicy evaluateServerTrust:forDomain:]` 对保护空间中的 `serverTrust` 以及域名 `host` 进行认证


根据认证的结果,会在 `completionHandler` 中传入不同的 `disposition` 和 `credential` 参数。


## 小结


+ `AFSecurityPolicy` 同样也作为一个即插即用的模块,在 AFNetworking 中作为验证 HTTPS 证书是否有效的模块存在,在 iOS 对 HTTPS 日渐重视的今天,在我看来,使用 HTTPS 会成为今后 API 开发的标配。



## 相关文章


关于其他 AFNetworking 源代码分析的其他文章:


+ [AFNetworking 概述(一)](https://github.com/Draveness/iOS-Source-Code-Analyze/blob/master/AFNetworking/AFNetworking%20概述(一).md)

+ [AFNetworking 的核心 AFURLSessionManager(二)](https://github.com/Draveness/iOS-Source-Code-Analyze/blob/master/AFNetworking/AFNetworking%20的核心%20AFURLSessionManager(二).md)

+ [处理请求和响应 AFURLSerialization(三)](https://github.com/Draveness/iOS-Source-Code-Analyze/blob/master/AFNetworking/处理请求和响应%20AFURLSerialization(三).md)

+ [AFNetworkReachabilityManager 监控网络状态(四)](https://github.com/Draveness/iOS-Source-Code-Analyze/blob/master/AFNetworking/AFNetworkReachabilityManager%20监控网络状态(四).md)

+ [验证 HTTPS 请求的证书(五)](https://github.com/Draveness/iOS-Source-Code-Analyze/blob/master/AFNetworking/验证%20HTTPS%20请求的证书(五).md)



<iframe src="http://ghbtns.com/github-btn.html?user=draveness&type=follow&size=large" height="30" width="240" frameborder="0" scrolling="0" style="width:240px; height: 30px;" allowTransparency="true"></iframe>


Follow: [@Draveness](https://github.com/Draveness)


Python的requests库发送HTTPS请求时,SSL证书验证的流程 关闭SSL证书验证意味着不会验证服务器返回的SSL证书是否有效和可信任,这使得你的应用容易受到中间人攻击的威胁。如果SSL证书验证失败(比如证书过期、证书不受信任、主机名不匹配等),requests库会抛出一个证书验证错误,连接将无法建立。:如果证书验证通过,requests库会使用SSL/TLS协议建立安全连接,确保通信的机密性和完整性。如果你遇到SSL证书验证失败的问题,应该尝试解决证书问题,而不是简单地关闭验证。,请确保你知道潜在的风险,并仔细评估在你的特定情况下是否可以接受这些风险。 阅读详情

相关推荐

PostMethod发送post请求忽略HTTPS证书验证

1.信任全部证书类MySSLProtocolSocketFactory import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; import java.net.U...

付士山哥 3114

sslpinning实战

知己知彼,百战不殆。看看证书绑定是怎么实现的!

碎片的博客 3127

【HarmonyOS NEXT】鸿蒙忽略证书验证抓包https请求

有很多小伙伴不知道学习哪些鸿蒙开发技术?不知道需要重点掌握哪些鸿蒙应用开发知识点?而且学习时频繁踩坑,最终浪费大量时间。所以有一份实用的。

m0_70749039的博客 2107

『IOS』Xcode工程中 添加AFNetworking出错_SecCertificateCreateWithData _SecTrustGetCertificateCount

Undefined symbols for architecture armv7:   "_SecTrustGetCertificateCount", referenced from:       -[AFURLConnectionOperation connection:willSendRequestForAuthenticationChallenge:] in AFURLConne

fallenink的专栏 1803

https之证书验证

1.中间人攻击对于http协议,中间人攻击(man in the middle)是一种著名的攻击方式。 图中John和Mary作为通信的双方,Frank为攻击者 1. John向Mary发送一段数据 2. Frank截获了John的包,窃取/修改数据后,伪装成John继续将包转发给Mary 3. Mary不知道Frank的存在,认为只是收到了来自John的数据,因为返回一段数据给John

Doarcutine的专栏 2万+

【CV论文精读】【协同感知综述】Collaborative Perception for Autonomous Driving :Current Status and Future Trend

感知是自动驾驶系统的关键模块之一,近年来取得了很大进展。然而,单个车辆的有限能力导致感知性能提高的瓶颈。为了突破个体感知的局限,协作感知被提出,它使车辆能够共享信息来感知视线和视野之外的环境。本文综述了有前途的协作感知技术的相关工作,包括介绍了基本概念,概括了协作模式,总结了协作感知的关键要素和应用。最后,我们讨论了这一研究领域面临的挑战和问题,并给出了一些潜在的进一步方向。

weixin_44184852的博客 4689

SecCertificate 解析

数字证书。

旭日的博客 738

告别手动点鼠标:用Python脚本批量跑ADS版图仿真,效率提升10倍(附完整代码)

本文详细介绍了如何利用Python脚本自动化ADS版图仿真流程,显著提升射频工程师的工作效率。通过调用ADS底层接口,实现参数化修改、批量任务调度和结果自动收集,解决了手动操作中的常见问题,如仿真不更新等。附完整代码,帮助开发者快速实现10倍效率提升。

weixin_42523543的博客 331

rsa从cer证书中拿公钥进行加密

起初,读召辉给的cer证书的时候, SecCertificateCreateWithData 总是返回为nil,原因是因为这个证书是服务器自己生成的,不是正规的CA机构颁发的,苹果安全性要求是很高的,所以这个读不出来,直接导致后面的崩溃。后来折腾了半天,比如直接从证书里面导出字符串作为公钥,也不行,安卓这样也是不行的。             后来迪哥又生成了个der证书,这样读就是正常

ios_xumin的专栏 6485

双臂复合机器人眼在手外标定实战:从原理到D435标定流程详解

本文详细解析了双臂复合机器人中眼在手外标定的核心原理与实战流程。通过阐述坐标系转换与AX=XB方程,重点介绍了使用Intel RealSense D435相机进行标定的完整步骤,包括环境搭建、数据采集、计算与验证,并提供了关键的避坑指南,帮助工程师实现相机与机械臂基座间的精确坐标对齐。

weixin_29100927的博客 445

Unity海洋渲染实战:Ceto Ocean System核心原理与高级应用指南

实时水面渲染是计算机图形学中的重要课题,涉及波浪模拟、光照交互和着色器编程等核心技术。其原理通常基于物理模型,如使用Gerstner波模拟规则海浪,或通过快速傅里叶变换(FFT)处理频谱数据生成随机海面。这些技术的价值在于能以可控的性能开销,在游戏中实现具有体积感、反射和折射效果的真实水体。在开放世界、海战模拟等应用场景中,专业的海洋系统如Ceto Ocean System,通过模块化架构整合了波浪生成、动态网格和渲染管线,为开发者提供了完整的解决方案。本文深入探讨了其双引擎波浪系统和多层渲染结构,并分享了

weixin_29002595的博客 278

ios https访问自建证书时遇到的问题

网上找到方法把证书加到bundle reosource里面: 然后使用下面的代码验证证书: - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { return [protec

u012673976的博客 2356

JMeter 压测实战全教程

脚本结构:测试计划 → 线程组 → HTTP 请求 → 监听器运行方式:图形化调试,命令行生产压测核心指标:QPS、RT、错误率、CPU、GC。

weixin_48309090的博客 651

HTTPS的数字证书验证原理

一、概述 网络请求方式通常分为两种,分别是HTTP请求和HTTPS请求,其中HTTP的传输属于明文传输,在传输的过程中容易被人截取并且偷窥其中的内容,而HTTPS是一种在HTTP的基础上加了SSL/TLS层(安全套接层)的安全的超文本传输协议,其传输的内容是通过加密得到的,所以说是一种安全的传输 二、加密算法 说到加密算法,先来了解一下两种常用的加密方式,分别是对称加密和非对称加密: ...

相忘于江湖 3万+

OPC UA 服务端的模拟工具及客户端工具

详细介绍如何使用 Prosys OPC UA Simulation Server 作为 OPC UA 服务端的模拟工具来生成数据模型,并使用 Softing OPC UA Client 作为客户端工具,直观地查看和验证模拟生成的数据。

weixin_44462773的博客 9853

11年电赛综合测评——单运放三角波发生器

目录 背景知识科普: 原理:局部负反馈+大环负反馈+积分器 仿真图如下: 背景知识科普: 反馈电路是将放大器输出信号(电压或电流)的一部分或全部,回收到放大器输入端与输入信号进行比较(相加或相减),并用比较所得的有效输入信号去控制输出,这就是放大器的反馈过程。 一、反馈放大器反馈极性的经验分析法—符号法 分析步骤1.在输入端上加上一个“+”或“-”的输入信号,按瞬时极性法标出反馈放大器中各个电极(基极b,集电极c,发射极e)电压的瞬时性。 2.判断经放大和反馈后得到的反馈信号Xf的瞬时极性

沉迷单车的追风少年 9905

HTTPS 请求中的证书验证详解(Python版)

有时候,你可能需要使用自定义的证书路径。requests你也可以使用自定义的验证器来处理证书验证。# 自定义的证书验证逻辑# 如果验证通过,返回 True;否则返回 False。

qq_41586251的博客 3702

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Java中HTTP接口请求与HTTPS证书验证问题

文章目录HTTP请求证书验证HTTPS通讯出错处理 HTTP是基于TCP/IP的应用层协议,简单、便捷。RESTFUL是一种基于HTTP的网络应用程序设计风格和开发方式,方便实现跨平台的业务接口。 HTTP请求 Java中通过HttpURLConnection可方便地进行HTTP请求: String sendRequest(String strUrl, String strMethod, String strBody) { String strResult = ""; try {

飞鹰技术 3206

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Python中处理HTTPS请求和SSL证书验证

else:通过将verify参数设置为自签名证书的路径,我们可以确保与内部服务的通信安全,同时避免因证书不受信任而导致的验证错误。requests库的设计理念体现了Python社区对易用性和强大功能的追求。它不仅简化了HTTPS请求的处理过程,还提供了丰富的高级功能,如会话管理、自定义证书验证等,使开发者能够在各种复杂场景下高效完成任务。无论是在小型项目还是大规模企业级应用中,requests库都能展现出其独特的优势。urllib库。

2401_86544677的博客 4653

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Https通信中证书验证流程

客户端验证服务器证书的有效性是一个多步骤的过程,涉及证书链验证、域名匹配、吊销检查等多个环节。但在某些场景下(如自定义客户端或嵌入式设备),可能需要手动处理证书验证逻辑。在 HTTPS 通信中,客户端验证服务器证书的有效性是确保通信安全的重要步骤。检查证书的 Not Before 和 Not After 字段。以下是将您提供的 HTTPS 证书验证流程转换为。返回证书链(服务器证书 + 中间证书)使用中间证书公钥验证服务器证书签名。检查证书的 SAN 或 CN 字段。使用根证书公钥验证中间证书签名。

Android资深专家,chromium 内核开发者 3304

Java实现通过证书访问Https请求

创建证书管理器类 import java.io.FileInputStream; import java.security.KeyStore; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.TrustManager;...

王绍桦 3万+

linux c++ curl https 请求并双向验证SSL证书

https://www.cnblogs.com/yongpan/p/8084854.html 1、配置curl https请求需要提供CA证书、客户端证书和客户端秘钥,这三个文件的pem格式。   分别对应 curl_easy_setopt() 函数的 下面三个参数:   CURLOPT_CAINFO - path to Certificate Authority (CA) bundle ...

chenyijun的专栏 6436

Https请求验证证书失败解决方法!(信任所有证书)

报错:unable to find valid certification path to requested target 解决办法: 1、导入证书到本地证书库 2、信任所有SSL证书 最好的解决办法或许是信任所有SSL证书,因为某些时候不能每次都手动的导入证书非常麻烦。现在封装了个方法,在连接openConnection的时候忽略掉证书就行了。 SslUtils.java imp...

YouAreMy_Sunshine的博客 1万+
上一篇: AFNetworkReachabilityManager 监控网络状态(四)
下一篇: 成熟的夜间模式解决方案
appdeveloperxg
博客等级 码龄11年 38粉丝 30原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值