- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 asmack(Android Gingerbread)连接到 google talk。我已经设置了 connectionConfig.setTruststoreType("BKS")
- 所以我解决了证书问题。现在失败发生在 XMPPConnection.proceedTLSReceived()
函数中,该函数在服务器为“starttls”请求发送“proceed”之后调用。
这个函数应该初始化 TSL 套接字。它失败并出现异常“java.net.SocketException:套接字已关闭”。
// Verify certificate presented by the server
context.init(kms,
new javax.net.ssl.TrustManager[]{new ServerTrustManager(getServiceName(), config)},
//new javax.net.ssl.TrustManager[]{new OpenTrustManager()},
new java.security.SecureRandom());
Socket plain = socket;
// Secure the plain connection
socket = context.getSocketFactory().createSocket(plain, plain.getInetAddress().getHostName(), plain.getPort(), false);
socket.setSoTimeout(0); ////// THIS LINE THROWS THE EXCEPTION
有什么线索吗?
套接字描述为:Socket 上的 SSL 套接字[addr=talk.google.com/173.194.70.125,port=5222,localport=34840]
它在模拟器和我的 Galaxy S I9000 上失败。
最佳答案
事实证明,SSL 连接存在超时问题。我的应用程序花费了太多时间来生成 SSL 套接字(通过普通套接字),以至于对方直接放弃了...这,或者存在关键问题(但我没有收到任何身份验证错误)。
我通过以下方式解决了这个问题:
我在下面发布了我的代码。 SASLXOAuth2 机制完成。但是 Main 中的代码是有条不紊的,并不完整。我从该站点上的其他答案中撕下了一些代码,我为我的剽窃提前道歉。
Main.java - 启动 asmack
// Init asmack, and register new mechanisms.
asmack = SmackAndroid.init(ctx);
SASLAuthentication.registerSASLMechanism("X-OAUTH2", SASLXOAuth2Mechanism.class);
SASLAuthentication.supportSASLMechanism("X-OAUTH2", 0);
ConnectionConfiguration connectionConfig =
new ConnectionConfiguration (getHost(), getPort(), getService());
connectionConfig.setSASLAuthenticationEnabled(true);
connectionConfig.setSecurityMode(true);
connectionConfig.setRosterLoadedAtLogin(true);
connectionConfig.setReconnectionAllowed(true);
connectionConfig.setSendPresence(false);
//connectionConfig.setCompressionEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
connectionConfig.setTruststoreType("AndroidCAStore");
connectionConfig.setTruststorePassword(null);
connectionConfig.setTruststorePath(null);
} /*else {
connectionConfig.setTruststoreType("BKS");
String path = System.getProperty("javax.net.ssl.trustStore");
if (path == null)
path = System.getProperty("java.home") + File.separator + "etc"
+ File.separator + "security" + File.separator
+ "cacerts.bks";
connectionConfig.setTruststorePath(path);
connectionConfig.setTruststorePassword("changeit");
//} */
XMPPConnection con = new XMPPConnection(connectionConfig);
SASLXOAuth2Mechanism.java - XOAuth2 机制
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.sasl.SASLMechanism;
import org.jivesoftware.smack.util.Base64;
import de.measite.smack.Sasl;
public class SASLXOAuth2Mechanism extends SASLMechanism
{
static final String AUTHENTICATOR_URL = "http://www.google.com/talk/protocol/auth";
protected String authenticationText = null;
static final String TAG = "SASLXOAuth2Mechanism";
public SASLXOAuth2Mechanism(SASLAuthentication saslAuthentication) {
super(saslAuthentication);
}
@Override
protected String getName()
{
return "X-OAUTH2";
}
@Override
public void authenticate(String username, String host, String password) throws IOException, XMPPException {
this.password = password;
this.authenticationId = username;
StringBuilder credentials = new StringBuilder();
credentials.append("\0");
credentials.append(username);
credentials.append("\0");
credentials.append(password);
authenticationText = Base64.encodeBytes(credentials.toString().getBytes("UTF-8"), Base64.DONT_BREAK_LINES);
String[] mechanisms = { "PLAIN" };
Map<String,String> props = new HashMap<String,String>();
sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this);
authenticate();
}
protected void authenticate() throws IOException, XMPPException {
// Send the authentication to the server
getSASLAuthentication().send(new XOAuth2AuthMechanism(getName(), authenticationText));
}
/**
* Initiating SASL authentication by select a mechanism.
*/
public class XOAuth2AuthMechanism extends Packet {
final private String name;
final private String authenticationText;
public XOAuth2AuthMechanism(String name, String authenticationText) {
super();
this.name = name;
this.authenticationText = authenticationText;
}
public String toXML() {
StringBuilder stanza = new StringBuilder();
stanza.append("<auth mechanism=\"").append(name);
stanza.append("\" xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" auth:service=\"oauth2\" xmlns:auth=\"").append(AUTHENTICATOR_URL);
stanza.append("\">");
if (authenticationText != null) {
stanza.append(authenticationText);
}
stanza.append("</auth>");
return stanza.toString();
}
}
}
关于android - (a) 击打 : TLS socket is closed when trying to login with XMPP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14623967/
基于 socket.io 的官方网站 http://socket.io/#how-to-use , 我找不到任何术语。socket.emit 、 socket.on 和 socket.send 之间有
我正在使用 lua-socket 3.0rc1.3(Ubuntu Trusty 附带)和 lua 5.1。我正在尝试监听 unix 域套接字,我能找到的唯一示例代码是 this -- send std
这两者有什么区别? 我注意到如果我在一个工作程序中从 socket.emit 更改为 socket.send ,服务器无法接收到消息,虽然我不明白为什么。 我还注意到,在我的程序中,如果我从 sock
使用套接字在两台服务器之间发送数据是个好主意,还是应该使用 MQ 之类的东西来移动数据。 我的问题:套接字是否可靠,如果我只需要一次/有保证的数据传输? 还有其他解决方案吗? 谢谢。 最佳答案 套接字
引自 this socket tutorial : Sockets come in two primary flavors. An active socket is connected to a
我已经安装了在端口81上运行的流服务器“Lighttpd”(light-tpd)。 我有一个C程序,它使用套接字api创建的服务器套接字在端口80上监听http请求。 我希望从客户端收到端口80上的请
这是我正在尝试做的事情: 当有新消息可用时,服务器会将消息发送给已连接的客户端。另一方面,客户端在连接时尝试使用send()向服务器发送消息,然后使用recv()接收消息,此后,客户端调用close(
如何将消息发送到动态 session 室,以及当服务器收到该消息时,如何将该消息发送到其他成员所在的同一个 session 室? table_id是房间,它将动态设置。 客户: var table_i
这是我尝试但不起作用的方法。我可以将传入的消息从WebSocket连接转发到NetSocket,但是只有NetSocket收到的第一个消息才到达WebSocket后面的客户端。 const WebSo
我正在实现使用boost将xml发送到客户端的服务器。我面临的问题是缓冲区不会立即发送并累积到一个点,然后发送整个内容。这在我的客户端造成了一个问题,当它解析xml时,它可能具有不完整的xml标记(不
尝试使用Nginx代理Gunicorn套接字。 /etc/systemd/system/gunicorn.service文件 [Unit] Description=gunicorn daemon Af
我正在使用Lua套接字和TCP制作像聊天客户端和服务器这样的IRC。我要弄清楚的主要事情是如何使客户端和服务器监听消息并同时发送它们。由于在服务器上执行socket:accept()时,它将暂停程序,
我看了一下ZMQ PUSH/PULL套接字,尽管我非常喜欢简单性(特别是与我现在正在通过UDP套接字在系统中实现的自定义碎片/ack相比),但我还是希望有自定义负载平衡功能,而不是幼稚的回合-robi
我正在编写一个应用程序,其中有多个 socket.io 自定义事件,并且所有工作正常,除了这个: socket.on("incomingImg", function(data) {
在我的应用程序中,我向服务器发送了两条小消息(类似 memcached 的服务)。在类似 Python 的伪代码中,这看起来像: sock.send("add some-key 0") ignored
很抱歉再次发布此问题,但大多数相关帖子都没有回答我的问题。我在使用 socket.io 的多个连接时遇到问题我没有使用“socket.socket.connect”方法,但我从第一次连接中得到了反馈。
我尝试使用 socket.io 客户端连接到非 socket.io websocket 服务器。但我做不到。我正在尝试像这样连接到套接字服务器: var socket = io.connect('ws
我遇到了一个奇怪的问题。在我非常基本的服务器中,我有: server.listen(8001); io.listen(server); var sockets = io.sockets; 不幸的是,套
我正在使用带套接字 io 的sailsjs。帆的版本是 0.10.5。我有以下套接字客户端进行测试: var socketIOClient = require('socket.io-client');
这个问题在这里已经有了答案: What is the fundamental difference between WebSockets and pure TCP? (4 个答案) 关闭 4 年前。
我是一名优秀的程序员,十分优秀!