软件安全不是安全软件。此处我们关注的主题包括身份验证、Access Control、机密性、加密和权限管理。
NSURLConnection
对象、NSURLSession
对象或 NSURLDownload
对象的代理负责评估信任链。 NSURLCredential
:
-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * credential)) completionHandler {
...
[challenge.sender useCredential:[NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
...
}
NSURLConnection
对象、NSURLSession
对象或 NSURLDownload
对象的代理负责评估信任链。 NSURLCredential
:
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
...
let cred = URLCredential(user: "foo", password: "bar", persistence: .none)
let trust = challenge.protectionSpace.serverTrust
let cred = URLCredential(trust:trust!)
...
}
NSURLConnection
对象、NSURLSession
对象或 NSURLDownload
对象的代理负责评估服务器信任。为了评估服务器信任,应在已从服务器 NSURLProtectionSpace
对象的 serverTrust
方法获取信任的情况下调用 SecTrustEvaluate(_:_:)
方法。 SecTrustEvaluate(_:_:)
方法返回两个不同的值:OSStatus
值表示结果代码。cancel(_:)
取消身份验证质询。
SecTrustRef trust = [[challenge protectionSpace] serverTrust];
SecTrustResultType result = kSecTrustResultInvalid;
OSStatus status = SecTrustEvaluate(trust, &result);
completionHandler(NSURLSessionAuthChallengeUseCredential, [challenge proposedCredential]);
NSURLConnection
对象、NSURLSession
对象或 NSURLDownload
对象的代理负责评估服务器信任。为了评估服务器信任,应在已从服务器 NSURLProtectionSpace
对象的 serverTrust
方法获取信任的情况下调用 SecTrustEvaluate(_:_:)
方法。 SecTrustEvaluate(_:_:)
方法返回两个不同的值:OSStatus
值表示结果代码。cancel(_:)
取消身份验证质询。
let trust = challenge.protectionSpace.serverTrust
var result = SecTrustResultType.invalid
let status = SecTrustEvaluate(trust!,&secresult)
completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, challenge.proposedCredential)
NSURLConnection
代理处理身份验证质询,而无需先验证应用程序是否知道如何处理特定保护空间的身份验证质询。NSURLProtectionSpace
对象代表需要身份验证的服务器或服务器上的某个区域(通常称为 Realm)。NSURLConnectionDelegate.connection(_:canAuthenticateAgainstProtectionSpace:)
方法之后立即调用应执行身份验证的 NSURLConnectionDelegate.connection(_:didReceive:)
方法。这样,NSURLConnectionDelegate
便可在尝试对保护空间进行身份验证之前检查它。通过返回 true
,代理指示它可以处理身份验证,在对 connection(_:didReceive:)
的后续调用中它也确实这样做了。如果您的代理未实施此方法且保护空间使用客户端证书身份验证或服务器信任身份验证,系统将会尝试使用用户的密钥链来验证哪些可能不是所需的行为。NSURLConnection
代理处理身份验证质询,而无需先验证应用程序是否知道如何处理特定保护空间的身份验证质询。NSURLProtectionSpace
对象代表需要身份验证的服务器或服务器上的某个区域(通常称为 Realm)。NSURLConnectionDelegate.connection(_:canAuthenticateAgainstProtectionSpace:)
方法之后立即调用应执行身份验证的 NSURLConnectionDelegate.connection(_:didReceive:)
方法。这样,NSURLConnectionDelegate
便可在尝试对保护空间进行身份验证之前检查它。通过返回 true
,代理指示它可以处理身份验证,在对 connection(_:didReceive:)
的后续调用中它也确实这样做了。如果您的代理未实施此方法且保护空间使用客户端证书身份验证或服务器信任身份验证,系统将会尝试使用用户的密钥链来验证哪些可能不是所需的行为。NSURLConnection
或 NSURLSession
的身份验证处理回调无法检查它正将凭证发送到哪个主机。NSURLConnection
或 NSURLSession
回调以处理身份验证请求。如果忘记确保身份验证请求来自于预期主机,凭证会发送到应用程序所加载的每个 URL。此外,如果无法检查是否能安全发送凭证,则会导致凭证被盗。
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NS URLAuthenticationChallenge *)challenge completionHandler:(void (^)(NS URLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler {
NSString *user = [self getUser];
NSString *pass = [self getPassword];
NSURLCredential *cred = [NSURLCredential credentialWithUser:user
password:pass persistence:NSURLCredentialPersistenceForSession];
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
}
NSURLConnection
或 NSURLSession
的身份验证处理回调无法检查它正将凭证发送到哪个主机。NSURLConnection
或 NSURLSession
回调以处理身份验证请求。如果忘记确保身份验证请求来自于预期主机,凭证会发送到应用程序所加载的每个 URL。此外,如果无法检查是否能安全发送凭证,则会导致凭证被盗。
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
let user = getUser()
let pass = getPassword()
let credential = URLCredential(user: user, password: pass, persistence: .none)
completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, credential)
}
tx.origin
进行授权。tx.origin
全局变量保存发起交易的帐户地址。tx.origin
包含帐户 A1 的地址,用于调用 S1。如果 tx.origin
的意图是验证 A1 的授权,那么将绕过此授权。tx.origin
获得授权,然后 tx.origin
将保存发起交易的用户帐户的地址,并且将绕过授权。tx.origin
相同,然后才能将资金转到提供的地址。sendTo
函数,然后 require
语句中的条件将为 true,并且会将资金转到攻击者合约在调用 sendTo
时指定的任何地址。
function sendTo(address receiver, uint amount) public {
require(tx.origin == owner);
receiver.transfer(amount);
}
22
的 AWS 安全组 (0.0.0.0/0
),其中 SSH 服务器通常响应传入的连接请求。
- name: Task to open SSH port
amazon.aws.ec2_group:
name: demo_security_group
description: Open the ssh port to the world
state: present
vpc_id: 123456
region: us-west-1
rules:
- proto: tcp
ports: 22
cidr_ip: 0.0.0.0/0
- name: Create Lambda policy statement for S3 event notification
community.aws.lambda_policy:
action: lambda:InvokeFunction
function_name: functionName
principal: *
statement_id: lambda-s3-demobucket-access-log
source_arn: arn:aws:s3:us-west-2:123456789012:demobucket
source_account: 123456789012
state: present