我有一个网站,我正在为一个RESTful服务启用ssl.我们已在RapidSSL注册,安装了证书,并通过了RapidSSL检查程序.我可以使用各种浏览器访问该网站,包括Android浏览器(内置,Firefox和Opera),没有任何问题,没有警告.
但是,当我尝试使用我的Android应用程序访问它时,我得到以下异常:
08-11 20:04:05.586 363 381 E HttpProvider: Error executing request: No peer certificate
08-11 20:04:05.586 363 381 E HttpProvider: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
08-11 20:04:05.586 363 381 E HttpProvider: at org.apache.harmony.xnet.provider.jsse.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:259)
08-11 20:04:05.586 363 381 E HttpProvider: at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)
08-11 20:04:05.586 363 381 E HttpProvider: at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)
08-11 20:04:05.586 363 381 E HttpProvider: at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:164)
08-11 20:04:05.586 363 381 E HttpProvider: at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-11 20:04:05.586 363 381 E HttpProvider: at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-11 20:04:05.586 363 381 E HttpProvider: …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个使用javax.mail API发送邮件的SSL客户端.我遇到的问题是服务器请求我使用SSL,但服务器也配置了非标准的SSL证书.我发现的网页说我需要将证书安装到信任库中.我不想这样做(我没有必要的权限.)
在发出Https请求时,如何避免"javax.net.ssl.SSLPeerUnverifiedException:peer not authenticated"异常和Android Apache lib间隙"构造函数SSLSocketFactory(SSLContext)未定义"?
我一直在努力让这个工作.我正在尝试使用自签名证书通过https连接到我的服务器.我不认为现在还没有任何页面或示例.
我做了什么:
它用于openssl s_client -connect domain.com:443从服务器获取证书.然后使用充气城堡创建一个bks密钥库.
从原始文件夹中读取创建的密钥库,将其添加到sslfactory,然后再添加到OkHttpClient.像这样:
public ApiService() {
mClient = new OkHttpClient();
mClient.setConnectTimeout(TIMEOUT_SECONDS, TimeUnit.SECONDS);
mClient.setReadTimeout(TIMEOUT_SECONDS, TimeUnit.SECONDS);
mClient.setCache(getCache());
mClient.setCertificatePinner(getPinnedCerts());
mClient.setSslSocketFactory(getSSL());
}
protected SSLSocketFactory getSSL() {
try {
KeyStore trusted = KeyStore.getInstance("BKS");
InputStream in = Beadict.getAppContext().getResources().openRawResource(R.raw.mytruststore);
trusted.load(in, "pwd".toCharArray());
SSLContext sslContext = SSLContext.getInstance("TLS");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trusted);
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
return sslContext.getSocketFactory();
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
public CertificatePinner getPinnedCerts() {
return new CertificatePinner.Builder()
.add("domain.com", "sha1/theSha=")
.build();
} …Run Code Online (Sandbox Code Playgroud)我正在尝试使用loopj来进行异步 HTTP请求.工作得很好,除非我尝试使用自签名证书访问https站点.我明白了
javax.net.ssl.SSLPeerUnverifiedException: No peer certificate.
Run Code Online (Sandbox Code Playgroud)
我想默认的ssl选项可以覆盖使用setSSLSocketFactory(SSLSocketFactory sslSocketFactory)方法,但我不知道该怎么做,或者它可能根本不是正确的方法.
请建议我该如何解决这个问题?
我试图通过从Android应用程序向PHP服务器发布数据来将记录插入MySQL.我已经向AndroidManifest.xml添加了INTERNET权限
我明白了 javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
Android代码
private void senddata(ArrayList<NameValuePair> data)
{
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://10.0.2.2/insert222.php");
httppost.setEntity(new UrlEncodedFormEntity(data));
HttpResponse response = httpclient.execute(httppost);
}
catch (Exception e) {
// TODO: handle exception
Log.e("log_tag", "Error: "+e.toString());
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
目前我正在编写一个java库来访问pointhq.com的REST API.
在开发Android客户端时,我意识到默认情况下不接受SSL证书,因此我编写了一个自定义TrustManager并添加了pointhq.com证书,如本文所述:使用HttpClient通过HTTPS信任所有证书
使用此Trustmanager和我导入的bks文件,我在尝试连接时收到以下错误: IssuerName(CN=GeoTrust Global CA, O=GeoTrust Inc., C=US) does not match SubjectName(CN=RapidSSL CA, O="GeoTrust, Inc.", C=US) of signing certificate.
那我做错了什么?我导入了pointhq.com,rapidssl.com,geotrust.com证书.但没有改变.是否有一种我必须注意的证书分类?我错过了根证书吗?
编辑:这是导入证书的列表:
类型:BKS提供者:BC条目:3
条目别名:geotrust global ca创建日期:19.10.2011 15:44:35 MESZ类型:可信证书证书:1
Certificate 1 of 1
Version: 3
Subject: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US
Issuer: CN=GeoTrust Global CA, O=GeoTrust Inc., C=US
Serial Number: 0002 3456
Valid From: 21.05.2002 06:00:00
Valid Until: 21.05.2022 06:00:00
Public Key: RSA (2.048 bits)
Signature Algorithm: SHA1withRSA
SHA-1 Fingerprint: DE:28:F4:A4:FF:E5:B9:2F:A3:C5:03:D1:A3:49:A7:F9:96:2A:82:12
MD5 Fingerprint: F7:75:AB:29:FB:51:4E:B7:77:5E:FF:05:3C:99:8E:F5
Run Code Online (Sandbox Code Playgroud)
输入别名:pointhq.com(rapidssl ca)创建日期:29.09.2011 18:55:12 MESZ类型:可信证书证书:1 …
我有一个移动应用程序(iPhone和Android),允许用户登录他的帐户,更改首选项等...
我想添加一个新功能,用户可以通过他的设备购买产品或升级他的服务.一切都将从设备运行,我想让用户使每个事务同步到Web服务器.
我的服务器上有HTTPS设置.我想知道是否:
谢谢
我在Android应用程序中使用官方Facebook SDK.用户登录后,我可以获取uid和facebook用户的名称,如下所示:
Facebook mFacebook = new Facebook(APP_ID);
// ... user logs in ...
//String jsonUser = mFacebook.request("me/picture"); // throws error
String jsonUser = mFacebook.request("me");
JSONObject obj = Util.parseJson(jsonUser);
String facebookId = obj.optString("id");
String name = obj.optString("name");
Run Code Online (Sandbox Code Playgroud)
我也知道我可以使用这些链接访问个人资料图片:
https://graph.facebook.com/<facebookId>/picture
https://graph.facebook.com/<facebookId>/picture?type=large
Run Code Online (Sandbox Code Playgroud)
我很乐意使用此代码来查看个人资料图片:
public static Drawable getPictureForFacebookId(String facebookId) {
Drawable picture = null;
InputStream inputStream = null;
try {
inputStream = new URL("https://graph.facebook.com/" + facebookId + "/picture").openStream();
} catch (Exception e) {
e.printStackTrace();
return null;
}
picture = Drawable.createFromStream(inputStream, "facebook-pictures");
return picture;
} …Run Code Online (Sandbox Code Playgroud) 我使用两种方法尝试使用HTTPS URL:
具有正确值的旧的已弃用和返回响应.
这是代码,它不需要忽略ssl证书它自己忽略它或可能使用其他技术:
public String newApiPost(String url,String p1,String p2,String p3){
HttpClient httpClient = new DefaultHttpClient();
// replace with your url
HttpPost httpPost = new HttpPost(url);
//Post Data
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>
();
nameValuePair.add(new BasicNameValuePair("cliend_id",p1));
nameValuePair.add(new BasicNameValuePair("client_secret", p2));
nameValuePair.add(new BasicNameValuePair("key",p3));
//Encoding POST data
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
// log exception
e.printStackTrace();
}
//making POST request.
try {
HttpResponse response = httpClient.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
String result = EntityUtils.toString(httpEntity,
HTTP.UTF_8);
Log.d("response", result);
// write …Run Code Online (Sandbox Code Playgroud) android ×8
ssl ×6
java ×4
https ×3
apache ×1
bouncycastle ×1
certificate ×1
facebook ×1
image ×1
lamp ×1
loopj ×1
okhttp ×1
openssl ×1
security ×1
transactions ×1
truststore ×1
url ×1