public void InitiateHandShake() { IPeerNeighbor neighbor = host; Message reply = null; Fx.Assert(host != null, "Cannot initiate security handshake without a host!"); //send the RST message. using (OperationContextScope scope = new OperationContextScope(new OperationContext((ServiceHostBase)null))) { PeerHashToken token = this.securityManager.GetSelfToken(); Message request = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, TrustFeb2005Strings.RequestSecurityToken, new PeerRequestSecurityToken(token)); bool fatal = false; try { reply = neighbor.RequestSecurityToken(request); if (!(reply != null)) { throw Fx.AssertAndThrow("SecurityHandshake return empty message!"); } ProcessRstr(neighbor, reply, PeerSecurityManager.FindClaim(ServiceSecurityContext.Current)); } catch (Exception e) { if (Fx.IsFatal(e)) { fatal = true; throw; } DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); this.state = PeerAuthState.Failed; if (DiagnosticUtility.ShouldTraceError) { ServiceSecurityContext context = ServiceSecurityContext.Current; ClaimSet claimSet = null; if (context != null && context.AuthorizationContext != null && context.AuthorizationContext.ClaimSets != null && context.AuthorizationContext.ClaimSets.Count > 0) { claimSet = context.AuthorizationContext.ClaimSets[0]; } PeerAuthenticationFailureTraceRecord record = new PeerAuthenticationFailureTraceRecord( meshId, neighbor.ListenAddress.EndpointAddress.ToString(), claimSet, e); TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.PeerNodeAuthenticationFailure, SR.GetString(SR.TraceCodePeerNodeAuthenticationFailure), record, this, null); } neighbor.Abort(PeerCloseReason.AuthenticationFailure, PeerCloseInitiator.LocalNode); } finally { if (!fatal) { request.Close(); } } } }
public void InitiateHandShake() { IPeerNeighbor host = this.host; Message message = null; using (new OperationContextScope(new OperationContext(null))) { PeerHashToken selfToken = this.securityManager.GetSelfToken(); Message request = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "RequestSecurityToken", (BodyWriter) new PeerRequestSecurityToken(selfToken)); bool flag = false; try { message = host.RequestSecurityToken(request); if (message == null) { throw Fx.AssertAndThrow("SecurityHandshake return empty message!"); } this.ProcessRstr(host, message, PeerSecurityManager.FindClaim(ServiceSecurityContext.Current)); } catch (Exception exception) { if (Fx.IsFatal(exception)) { flag = true; throw; } DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information); this.state = PeerAuthState.Failed; if (DiagnosticUtility.ShouldTraceError) { ServiceSecurityContext current = ServiceSecurityContext.Current; ClaimSet claimSet = null; if (((current != null) && (current.AuthorizationContext != null)) && ((current.AuthorizationContext.ClaimSets != null) && (current.AuthorizationContext.ClaimSets.Count > 0))) { claimSet = current.AuthorizationContext.ClaimSets[0]; } PeerAuthenticationFailureTraceRecord extendedData = new PeerAuthenticationFailureTraceRecord(this.meshId, host.ListenAddress.EndpointAddress.ToString(), claimSet, exception); TraceUtility.TraceEvent(TraceEventType.Error, 0x4004d, System.ServiceModel.SR.GetString("TraceCodePeerNodeAuthenticationFailure"), extendedData, this, null); } host.Abort(PeerCloseReason.AuthenticationFailure, PeerCloseInitiator.LocalNode); } finally { if (!flag) { request.Close(); } } } }