当前位置: 首页>>代码示例>>Golang>>正文


Golang MessageReadWriteCloser.Read方法代码示例

本文整理汇总了Golang中github.com/AdRoll/hologram/protocol.MessageReadWriteCloser.Read方法的典型用法代码示例。如果您正苦于以下问题:Golang MessageReadWriteCloser.Read方法的具体用法?Golang MessageReadWriteCloser.Read怎么用?Golang MessageReadWriteCloser.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/AdRoll/hologram/protocol.MessageReadWriteCloser的用法示例。


在下文中一共展示了MessageReadWriteCloser.Read方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: SSHChallenge

/*
SSHChallenge performs the challenge-response process to authenticate a connecting client to its SSH keys.
*/
func (sm *server) SSHChallenge(m protocol.MessageReadWriteCloser) (*User, error) {
	for {
		challenge := make([]byte, 64)
		for i := 0; i < len(challenge); i++ {
			challenge[i] = byte(rand.Int() % 256)
		}

		response := &protocol.Message{
			ServerResponse: &protocol.ServerResponse{
				Challenge: &protocol.SSHChallenge{
					Challenge: challenge,
				},
			},
		}

		err := m.Write(response)
		if err != nil {
			return nil, err
		}

		challengeResponseMessage, err := m.Read()
		if err != nil {
			return nil, err
		}

		r := challengeResponseMessage.GetServerRequest()
		if r == nil {
			return nil, errors.New("not a server request")
		}
		cr := r.GetChallengeResponse()
		if cr == nil {
			return nil, errors.New("not a server request")
		}

		// Compose this into the proper format for Authenticate.
		sig := &ssh.Signature{
			Format: cr.GetFormat(),
			Blob:   cr.GetSignature(),
		}
		verifiedUser, err := sm.authenticator.Authenticate("derp", challenge, sig)
		if err != nil {
			return nil, err
		}
		if verifiedUser != nil {
			log.Debug("Verification completed for user %s!", verifiedUser.Username)
			return verifiedUser, nil
		}
		// continue around the loop, letting the client try another key
		verificationFailure := &protocol.Message{
			ServerResponse: &protocol.ServerResponse{
				VerificationFailure: &protocol.SSHVerificationFailure{},
			},
		}
		err = m.Write(verificationFailure)
		if err != nil {
			return nil, err
		}

	}
}
开发者ID:graphaelli,项目名称:hologram,代码行数:63,代码来源:server.go

示例2: testHandler

func testHandler(msc protocol.MessageReadWriteCloser) {
	for {
		msg, _ := msc.Read()

		if pingReq := msg.GetPing(); pingReq != nil {
			pingResp := protocol.Ping_RESPONSE
			msc.Write(&protocol.Message{
				Ping: &protocol.Ping{
					Type: &pingResp,
				},
			})
		}

	}
}
开发者ID:nathanpalmer,项目名称:hologram,代码行数:15,代码来源:remote_test.go

示例3: DummyServer

func DummyServer(c protocol.MessageReadWriteCloser) {
	for {
		msg, err := c.Read()
		if err != nil {
			return
		}

		if msg.GetServerRequest() != nil {
			serverRequest := msg.GetServerRequest()

			accessKey := "access"
			secret := "secret"
			token := "token"
			exp := int64(0)

			if serverRequest.GetAssumeRole() != nil {
				challenge := &protocol.Message{
					ServerResponse: &protocol.ServerResponse{
						Challenge: &protocol.SSHChallenge{
							Challenge: []byte("foo"),
						},
					},
				}
				err = c.Write(challenge)
			} else if serverRequest.GetChallengeResponse() != nil {
				creds := &protocol.Message{
					ServerResponse: &protocol.ServerResponse{
						Credentials: &protocol.STSCredentials{
							AccessKeyId:     &accessKey,
							SecretAccessKey: &secret,
							AccessToken:     &token,
							Expiration:      &exp,
						},
					},
				}
				err = c.Write(creds)
			}
		}
	}
}
开发者ID:nathanpalmer,项目名称:hologram,代码行数:40,代码来源:client_test.go

示例4: HandleConnection

/*
ConnectionHandler is the root of the state machine created for
each socket that is opened.
*/
func (sm *server) HandleConnection(m protocol.MessageReadWriteCloser) {
	// Loop as long as we have this connection alive.
	log.Debug("Opening new connection handler.")
	for {
		recvMsg, err := m.Read()
		if err != nil {
			// EOFs are normal, so we don't want to report them as errors.
			if err.Error() != "EOF" {
				log.Errorf("Error reading data from stream: %s", err.Error())
			}
			// Right now the behaviour of this is to terminate the connection
			// when we run into an error; should it perhaps send a NAK response
			// and keep the connection open for another retry?
			break
		}

		if pingMsg := recvMsg.GetPing(); pingMsg != nil {
			sm.HandlePing(m, pingMsg)
		} else if reqMsg := recvMsg.GetServerRequest(); reqMsg != nil {
			sm.HandleServerRequest(m, reqMsg)
		}
	}
}
开发者ID:graphaelli,项目名称:hologram,代码行数:27,代码来源:server.go

示例5: HandleConnection

func (h *cliHandler) HandleConnection(c protocol.MessageReadWriteCloser) {
	for {
		msg, err := c.Read()
		if err != nil {
			return
		}
		if msg.GetAgentRequest() != nil {
			dr := msg.GetAgentRequest()

			var (
				sshAgentSock string
				sshKeyBytes  []byte
			)

			sshAgentSock = dr.GetSshAgentSock()
			if sshAgentSock != "" {
				log.Debug("SSH_AUTH_SOCK included in this request: %s", sshAgentSock)
			}

			sshKeyBytes = dr.GetSshKeyFile()
			if sshKeyBytes != nil {
				log.Debug("SSH keyfile included in this request.")
			}

			SSHSetAgentSock(sshAgentSock, sshKeyBytes)

			if dr.GetAssumeRole() != nil {
				log.Debug("Handling AssumeRole request.")
				assumeRole := dr.GetAssumeRole()

				err := h.client.AssumeRole(assumeRole.GetRole())

				var agentResponse protocol.AgentResponse
				if err == nil {
					agentResponse.Success = &protocol.Success{}
				} else {
					log.Errorf(err.Error())
					e := err.Error()
					agentResponse.Failure = &protocol.Failure{
						ErrorMessage: &e,
					}
				}
				msg = &protocol.Message{
					AgentResponse: &agentResponse,
				}
				err = c.Write(msg)
				if err != nil {
					return
				}
			} else if dr.GetGetUserCredentials() != nil {
				log.Debug("Handling GetSessionToken request.")
				err := h.client.GetUserCredentials()

				var agentResponse protocol.AgentResponse
				if err == nil {
					agentResponse.Success = &protocol.Success{}
				} else {
					log.Errorf(err.Error())
					e := err.Error()
					agentResponse.Failure = &protocol.Failure{
						ErrorMessage: &e,
					}
				}
				msg = &protocol.Message{
					AgentResponse: &agentResponse,
				}
				err = c.Write(msg)
				if err != nil {
					return
				}
			} else {
				log.Errorf("Unexpected agent request: %s", dr)
				c.Close()
				return
			}
		} else {
			log.Errorf("Unexpected message: %s", msg)
			c.Close()
			return
		}
	}
}
开发者ID:nathanpalmer,项目名称:hologram,代码行数:82,代码来源:cli_handler.go


注:本文中的github.com/AdRoll/hologram/protocol.MessageReadWriteCloser.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。