軟體安全性並非安全性軟體。我們關注驗證、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
物件可代表需要驗證的伺服器或伺服器上的區域 (通常稱為領域)。NSURLConnectionDelegate.connection(_:didReceive:)
方法之前呼叫 NSURLConnectionDelegate.connection(_:canAuthenticateAgainstProtectionSpace:)
方法。這允許 NSURLConnectionDelegate
先檢查保護空間,然後再嘗試進行驗證。透過傳回 true
,委派表示其可處理驗證表單 (將在後續呼叫 connection(_:didReceive:)
時執行)。如果您的委派未執行此方法,而保護空間使用用戶端憑證驗證或伺服器信任驗證,則系統將嘗試使用使用者的金鑰鏈來驗證哪些可能不是想要的運作方式。NSURLConnection
委派會直接處理驗證挑戰,而不會先驗證應用程式是否瞭解如何針對特定保護空間處理驗證挑戰。NSURLProtectionSpace
物件可代表需要驗證的伺服器或伺服器上的區域 (通常稱為領域)。NSURLConnectionDelegate.connection(_:didReceive:)
方法之前呼叫 NSURLConnectionDelegate.connection(_:canAuthenticateAgainstProtectionSpace:)
方法。這允許 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);
}
0.0.0.0/0
) (即 TCP 連接埠 22
) 開放的 AWS 安全性群組,其中 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