betway必威亚洲官网 9

linux系统编程,https遇到自签名证书

我的环境是ubuntu16.04

对于CA机构颁发的证书Okhttp默认支持
可以直接访问

Python基础

glibc官网:

但是对于自定义的证书就不可以了(如:https
://kyfw.12306.cn/otn/),
需要加入Trust

对于Python,一切事物都是对象,对象基于类创建

betway必威亚洲官网 1

方法一、一般来说,涉及到库调用的程序,在链接时候都会链接到glibc,所以,可以用ldd命令来查看

下面分两部分来写,一是信任所有证书,二是信任指定证书,访问自签名的网站

所以,以下这些值都时对象:”zhurui”、22、[‘北京’,’上海’,’深圳’],并且是根据不同的类生成的对象。

betway必威亚洲官网 2

 

betway必威亚洲官网 3

betway必威亚洲官网 4

ghostwu@ubuntu:~/c_program/linux_unix/chapter4$ ldd ./pwd | grep libc
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7c45491000)
ghostwu@ubuntu:~/c_program/linux_unix/chapter4$ /lib/x86_64-linux-gnu/libc.so.6 
GNU C Library (Ubuntu GLIBC 2.23-0ubuntu9) stable release version 2.23, by Roland McGrath et al.
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 5.4.0 20160609.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.

一、信任所有证书

1. 在你的module
下 build.gradule里添加

dependencies {
、、、
compile 'com.zhy:okhttputils:2.6.2'
、、、}

2.新建MyApplication

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        // 这就是信任所有证书
        HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null,null, null);
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                    .connectTimeout(10000L, TimeUnit.MILLISECONDS)
                    .readTimeout(10000L, TimeUnit.MILLISECONDS)
                    .addInterceptor(new LoggerInterceptor("TAG"))
                    .hostnameVerifier(new HostnameVerifier() {
                        @Override
                        public boolean verify(String hostname, SSLSession session) {
                            return true;
                        }
                    })
                    .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
                    .build();
            OkHttpUtils.initClient(okHttpClient);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

3.AndroidMainfest.xml

//添加权限
 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

    <application
        //将新建的MyApplication name添加进来
        android:name=".MyApplication"
        .....

4.然后在需要请求网络的地方

public void getHttps(View view) {
        String url = "https://kyfw.12306.cn/otn/";

        OkHttpUtils
                .get()
                .url(url)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "onError: " + e.toString());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "onResponse: " + response.toString());
                    }
                });
    }

一、基本数据类型

这个就是我的电脑上glibc的路径:/lib/x86_64-linux-gnu/libc.so.6

二、自定义的证书 自签名网站

分两种:1.直接使用网站证书;2.将证书转为字符串

数字(int)

如:21、45、56

每一个整数都具备如下功能:

 

 1 - int
 2  将字符串转换为数字
 3 例子:
 4 a = "123"
 5 print(type(a),a)
 6 输出结果:
 7 >>> a = "123"
 8 >>> print(type(a),a)
 9 <class 'str'> 123
10 
11 b = int(a)
12 print(type(b),b)
13 
14 输出结果:
15 >>> b = int(a)
16 >>> print(type(b),b)
17 <class 'int'> 123
18 
19 num = "0022"
20 v = int(num, base=16)
21 print(v)
22 
23 输出结果:
24 >>> num = "0022"
25 >>> v = int(num, base=16)
26 >>> print(v)
27 34
28 
29 - bit_length
30  #当前数字的二进制,至少用n位表示
31 age = 22
32 v = age.bit_length()
33 print(v)
34 
35 输出结果:
36 >>> age = 22
37 >>> v = age.bit_length()
38 >>> print(v)
39 5

方法二:man -k
glibc,可以找到一个系统函数gnu_get_libc_version,他可以用来获取版本

1、直接使用网站证书###\

1.导出网站证书

— chrome浏览器方法:(其他浏览器请百度)

–访问
https://kyfw.12306.cn/otn/

按F12

 

betway必威亚洲官网 5


详细信息–复制到文件–下一步

— 选

 

betway必威亚洲官网 6

 

–下一步

–选择保存位置 填入文件名

 

betway必威亚洲官网 7

–下一步
–完成–确定

2、将导出的证书 放在assets文件夹下,没有就自己创建一个

 

betway必威亚洲官网 8

//使用  在Application里 
HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(new InputStream[]{getAssets().open("srca.cer")}, null, null);

==========

betway必威亚洲官网,也可以不用证书 直接将证书转为字符串 ,使用字符串

字符串(str)

1、name.capitalize() 
 #首字母大写

例子:

>>> test = "zhUrui"
>>> v = test.capitalize()
>>> print(v)
Zhurui

 

2、name.casefold() 
 #所有变小写,casefold更牛逼,很多未知的对相应变小写

例子:

>>> test = "zhUrui"
>>> v1 = test.casefold()
>>> print(v1)
zhurui
>>> v2 = test.lower()
>>> print(v2)
zhurui

 

3、name.center() 
#设置宽度,并将内容居中 

   name.ljust()   #设置宽度,变量向左,其他部分用所定义的填充符 填充

   name.rjust()  #设置宽度,变量向右,其他部分用所定义的填充符 填充

      name.zfill() 
#设置宽度,默认变量向右,其他部分用zfill方法特定的填充符”000″ 填充

>>> test = "zhurui"
>>> v = test.center(20,"中")
>>> print(v)
中中中中中中中zhurui中中中中中中中

解释:
#  20   代指总长度
#   *    空白未知填充,一个字符,可有可无

输出结果:
中中中中中中中zhurui中中中中中中中
##########################################
>>> test = "zhurui"
>>> v = test.ljust(20,"*") #ljust 变量靠左,其他部分用*填充
>>> print(v)
zhurui**************

##################################
>>> test = "zhurui"
>>> v = test.rjust(20,"*") #rjust 变量靠右,其他部分用*填充
>>> print(v)
**************zhurui

>>> test = "zhurui"
>>> v = test.zfill(20)  ##zfill只能用于000填充
>>> print(v)
00000000000000zhurui

 

 4、name.count() 
 #去字符串中寻找,寻找子序列的出现次数

>>> test = "Zhuruizhuruiru"
>>> v = test.count('ru')
>>> print(v)
3
>>> v = test.count('z')
>>> print(v)
1

#########################################
>>> test = "Zhuruizhuruiru"
>>> v = test.count('ru', 5, 6)
>>> print(v)
0

 

5、name.encode() 
#将字符串编码成bytes格式

6、name.decode()

 

7、name.endswith(“ui”)  #判断字符串是否以ui结尾

   name.startswith(‘ui’)  #判断字符串是否以ui开始

>>> test = "zhurui"
>>> v = test.endswith('ui')
>>> print(v)
True
>>> v = test.startswith('ui')
>>> print(v)
False

 

 8、”Zhu\tRui”.expandtabs(10)  #输出‘Zhu          Rui’,
将\t转换为多长的空格

>>> test = "Zhu\tRui"
>>> v = test.expandtabs(10)
>>> print(v)
Zhu       Rui

################################
test = "username\tpassword\temail\nzhurui\t123456\t24731701@qq.com\nzhurui\t123456\t24731701@qq.com\nzhurui\t123456\t24731701@qq.com"
v = test.expandtabs(20)
print(v)

输出结果:

C:\Python35\python3.exe C:/Users/ZR/PycharmProjects/python全栈开发/day1/logging.py
username            password            email
zhurui              123456              24731701@qq.com
zhurui              123456              24731701@qq.com
zhurui              123456              24731701@qq.com

 

9、name.find(A) 
#从开始往后找,找到第一个之后,获取其位置即索引,找不到返回-1

## > 或 >=
# 未找到 -1
>>> test = "williamwilliam"
>>> v = test.find('am')
>>> print(v)
5
>>> v = test.find('t') #找变量中的"t"字符,
>>> print(v)
-1 ##没有找到,返回负一

 

10、name.index(‘a’)  #找不到,报错

>>> test = "williamwilliam"
>>> v = test.index('a')
>>> print(v)
5
>>> v = test.index('8')  ##找字符串中是否
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: substring not found

 

11、name.format()  #格式化,将一个字符串中的占位符替换为指定的值

>>> test = 'i am {name}, age {a}'
>>> print(test)
i am {name}, age {a}
>>> v = test.format(name='william',a=22)
>>> print(v)
i am william, age 22

 

>>> test = 'i am {0},age {1}'
>>> print(test)
i am {0},age {1}
>>> v = test.format('william', 22)
>>> print(v)
i am william,age 22

 

 12、name.format_map()
#格式化, 传入的值{“name”:  ‘william’,  “a”:  22}

>>> test = 'i am {name}, age {a}'
>>> v1 = test.format(name='zhurui',a=22)
>>> v2 = test.format_map({"name":'zhurui', "a": 19})
>>> print(v1)
i am zhurui, age 22
>>> print(v2)
i am zhurui, age 19

 

13、name.isalnum() #字符串中是否只包含  字母和数字

>>> test = "234"
>>> v = test.isalnum()
>>> print(v)
True

 

14、name.isalpha() #是否是字母,汉字

>>> test = "asfdge242"
>>> v = test.isalpha()
>>> print(v)
False
>>> test = "威廉"
>>> v = test.isalpha()
>>> print(v)
True

 

15、判断输入的是否是数字

>>> test = "二" # 1 , ②
>>> v1 = test.isdecimal   ##判断十进制小数
>>> v2 = test.isdigit()
>>> v3 = test.isnumeric()  ##判断汉语的数字,比如 "二"
>>> print(v1,v2,v3)
<built-in method isdecimal of str object at 0x00000201FE440AB0> False True

 

 16、name.isprintable() #判断是否存在不可显示的字符

\t  制表符
\n  换行
>>> test = "qepoetewt\tfdfde"
>>> v = test.isprintable()
>>> print(v)
False
>>> test = "qepoetewtfdfde"
>>> v = test.isprintable()
>>> print(v)
True

 

 17、name.isspace() #判断是否全部是空格

>>> test = ""
>>> v = test.isspace()
>>> print(v)
False
>>> test = " "
>>> v = test.isspace()
>>> print(v)
True

 

18、name.istitle() #判断是否是标题,其中必须首字母大写

>>> test = "Return True if all cased characters in S are uppercase"
>>> v1 = test.istitle()
>>> print(v1)
False
>>> v2 = test.title()  #将字符串首字母大写
>>> print(v2)
Return True If All Cased Characters In S Are Uppercase
>>> v3= v2.istitle()
>>> print(v3)
True

 

19、***** name.join()
#将字符串中的每一个元素按照指定分隔符进行拼接(五星重点参数)

>>> test = "出任CEO迎娶白富美"
>>> print(test)
出任CEO迎娶白富美
>>> v = '_'.join(test)
>>> print(v)
出_任_C_E_O_迎_娶_白_富_美
>>>

 

20、name.islower() #判断是否全部是大小写 和 转换为大小写

>>> test = "William"
>>> v1 =test.islower() #判断是否全都是小写
>>> v2 = test.lower()  #将变量转换为小写
>>> print(v1, v2)
False william
>>>

###################################

>>> test = "William"
>>> v1 =test.isupper() #判断是否全都是大写
>>> v2 = test.upper()  #将变量转换为大写
>>> print(v1, v2)
False WILLIAM

 

 21、移除指定字符串,优先最多匹配

>>> test = 'xa'
>>> v1 =test.isupper()
>>> v = test.lstrip("xa")
>>> print(v)

>>> v = test.rstrip("92exxxexxa")
>>> print(v)

>>> v = test.strip("xa")
>>> print(v)

###################################
# test.lstrip()
# test.rstrip()
# test.strip()
# 去除左右空白
# v = test.lstrip()
# v = test.rstrip()
# v = test.strip()
# print(v)
# print(test)
# 去除\t \n
# v = test.lstrip()
# v = test.rstrip()
# v = test.strip()
# print(v)

 

22、对应关系替换

>>> test = "aeiou"
>>> test1 = "12345"
>>> v = "asidufkasd;fiuadkf;adfkjalsdjf"
>>> m = str.maketrans("aeiou", "12345")
>>> new_v = v.translate(m)
>>> print(new_v)
1s3d5fk1sd;f351dkf;1dfkj1lsdjf

 

23、name.partition() #分割为三部分

>>> test = "testegerwerwegwewe"
>>> v = test.partition('s')
>>> print(v)
('te', 's', 'tegerwerwegwewe')
>>> v = test.rpartition('s')
>>> print(v)
('te', 's', 'tegerwerwegwewe')
>>>

 

24、name.split() #分格为指定个数

>>> test = "sagesgegessress"
>>> v = test.split('s',2)
>>> print(v)
['', 'age', 'gegessress']
>>>

 

25、分割, 只能根据,true, false:是否保留换行

>>> test = "fwerwerdf\frweqnndasfq\fnaqewrwe"
>>> v = test.splitlines(False)
>>> print(v)
['fwerwerdf', 'rweqnndasfq', 'naqewrwe']

 

26、以xxx开头,以xx结尾

>>> test = "backend 1.2.3.4"
>>> v = test.startswith('a')
>>> print(v)
False
>>> test.endswith('a')
False

 

27、name.swapcase() #大小写转换

>>> test = "WiiLiAm"
>>> v = test.swapcase()
>>> print(v)
wIIlIaM

 

28、name.isidentifier() #字母,数字,下划线  :标识符  def  class

>>> a = "def"
>>> v = a.isidentifier()
>>> print(v)
True

 

29、name.replace() #将指定字符串替换为指定字符串,替换功能相当于sed

>>> test = "williamwilliamwilliam"
>>> v = test.replace("am", "bbb")
>>> print(v)
willibbbwillibbbwillibbb
>>> v = test.replace("am", "bbb",2)
>>> print(v)
willibbbwillibbbwilliam
>>>
ghostwu@ubuntu:~$ man -k libc
cracklib-check (8)   - Check passwords using libcrack2
create-cracklib-dict (8) - Check passwords using libcrack2
curl-config (1)      - Get information about a libcurl installation
error (3)            - glibc error reporting functions
error_at_line (3)    - glibc error reporting functions
error_message_count (3) - glibc error reporting functions
error_one_per_line (3) - glibc error reporting functions
error_print_progname (3) - glibc error reporting functions
glibc (7)            - overview of standard C libraries on Linux
gnu_get_libc_release (3) - get glibc version and release
gnu_get_libc_version (3) - get glibc version and release
libc (7)             - overview of standard C libraries on Linux
ghostwu@ubuntu:~$ man 3 gnu_get_libc_version 

/*================================================================
*   Copyright (C) 2018 . All rights reserved.
*   
*   文件名称:check_glibc_version.c
*   创 建 者:ghostwu(吴华)
*   创建日期:2018年01月10日
*   描    述:获取GNU C库(glibc)的版本号
*
================================================================*/

#include <stdio.h>
#include <gnu/libc-version.h>

int main(int argc, char *argv[])
{
    printf( "glibc's version: %s\n", gnu_get_libc_version() );
    return 0;
}

2、将证书转为字符串###\

两种方式任选一种
直接使用证书 就不用这一步了

代码
http://download.csdn.net/download/eryhytkmgfhnghnjfghn/9834086

1.在你的module
下 build.gradule里添加

dependencies {
、、、
compile 'com.zhy:okhttputils:2.6.2'
、、、}

2.新建MyApplication

public class MyApplication extends Application {
          //获取12306网站证书,将证书中的内容提取出来,写成字符串常量
//不会提取内容 请百度
//我的在asli是可以直接看到内容的
            private String CER_12306 = "-----BEGIN CERTIFICATE-----\n" +
            "MIICmjCCAgOgAwIBAgIIbyZr5/jKH6QwDQYJKoZIhvcNAQEFBQAwRzELMAkGA1UEBhMCQ04xKTAn\n" +
            "BgNVBAoTIFNpbm9yYWlsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MQ0wCwYDVQQDEwRTUkNBMB4X\n" +
            "DTA5MDUyNTA2NTYwMFoXDTI5MDUyMDA2NTYwMFowRzELMAkGA1UEBhMCQ04xKTAnBgNVBAoTIFNp\n" +
            "bm9yYWlsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MQ0wCwYDVQQDEwRTUkNBMIGfMA0GCSqGSIb3\n" +
            "DQEBAQUAA4GNADCBiQKBgQDMpbNeb34p0GvLkZ6t72/OOba4mX2K/eZRWFfnuk8e5jKDH+9BgCb2\n" +
            "9bSotqPqTbxXWPxIOz8EjyUO3bfR5pQ8ovNTOlks2rS5BdMhoi4sUjCKi5ELiqtyww/XgY5iFqv6\n" +
            "D4Pw9QvOUcdRVSbPWo1DwMmH75It6pk/rARIFHEjWwIDAQABo4GOMIGLMB8GA1UdIwQYMBaAFHle\n" +
            "tne34lKDQ+3HUYhMY4UsAENYMAwGA1UdEwQFMAMBAf8wLgYDVR0fBCcwJTAjoCGgH4YdaHR0cDov\n" +
            "LzE5Mi4xNjguOS4xNDkvY3JsMS5jcmwwCwYDVR0PBAQDAgH+MB0GA1UdDgQWBBR5XrZ3t+JSg0Pt\n" +
            "x1GITGOFLABDWDANBgkqhkiG9w0BAQUFAAOBgQDGrAm2U/of1LbOnG2bnnQtgcVaBXiVJF8LKPaV\n" +
            "23XQ96HU8xfgSZMJS6U00WHAI7zp0q208RSUft9wDq9ee///VOhzR6Tebg9QfyPSohkBrhXQenvQ\n" +
            "og555S+C3eJAAVeNCTeMS3N/M5hzBRJAoffn3qoYdAO1Q8bTguOi+2849A==\n" +
            "-----END CERTIFICATE-----";
    @Override
    public void onCreate() {
        super.onCreate();
        // 这就是信任所有证书   **和 一 的区别在这里**
        //这里  import okio.Buffer;   
        HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(new InputStream[]{new Buffer().writeUtf8(CER_12306).inputStream()},null, null);
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                    .connectTimeout(10000L, TimeUnit.MILLISECONDS)
                    .readTimeout(10000L, TimeUnit.MILLISECONDS)
                    .addInterceptor(new LoggerInterceptor("TAG"))
                    .hostnameVerifier(new HostnameVerifier() {
                        @Override
                        public boolean verify(String hostname, SSLSession session) {
                            return true;
                        }
                    })
                    .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
                    .build();
            OkHttpUtils.initClient(okHttpClient);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

然后同一的34

 

betway必威亚洲官网 9

代码 https://github.com/DeadLine837/TestHttps

參考 https://github.com/hongyangAndroid/okhttputils

  

 字符串总结

################7个基本魔法#################
join    # '_'.join("asdfdfsdsf")
split
find
strip
upper
lower
replace(相当于sed替换功能)


################4个灰魔法#################
一、for循环
 格式:
 for 变量名 in  字符串:
      变量名
break
continue

例子:
test = "好看的妹子有种冲我来"
for item in test:
    print(item)
    break
输出结果为:
    好

例子2:
test = "好看的妹子有种冲我来"
index = 0
while index < len(test):
    v = test[index]
    print(v)
    index += 1
print('============')
输出结果为:
C:\Python35\python3.exe C:/Users/ZR/PycharmProjects/python全栈开发/day12/index1.py
好
看
的
妹
子
有
种
冲
我
来
============

例子3:(比较break跟continue的区别)
test = "好看的妹子有种冲我来"

for item in test:
     print(item)
     break
输出结果为:
 好

for item in test:
     print(item)
     continue
输出结果为:
C:\Python35\python3.exe C:/Users/ZR/PycharmProjects/python全栈开发/day12/index1.py
好
看
的
妹
子
有
种
冲
我
来

二、索引,下标,获取字符串中的某一个字符
test = "好看的妹子有种冲我来"
v = test[3]
print(v)
输出结果为:
妹

三、切片
v = test[0:1]  #标识大于等于0,小于1(0<= <1)
print(v)
输出结果为:
好

四、获取长度
Python3:  len获取当前字符串中由几个字符组成
v = len(test)
print(v)
输出结果为:
10

注意:
len("asdf")
for循环
索引
切片

五、获取连续或不连续的数字
Python2中直接创建在内容中
Python3中只有for循环时,才一个一个创建
例子:
r1 = range(10)
print(r1)
输出结果为:
10
range(0, 10)
执行for循环时:
才会一个一个创建打印
r2 = range(1,10)
r3 = range(1,10,2)
帮助创建连续的数字,通过设置步长来指定不连续
v = range(0, 100, 5) #括号中的5代表步长
for item in v:
    print(item)

 练习题:根据用户输入的值,输出每一个字符以及当前字符所在的索引位置

将文字  对应的索引打印出来:
方法1:

test = input(">>>")
print(test)   # test = qwe   test[0]   test[1]
l = len(test) # l = 3
print(l)

r = range(0,l) # 0,3
for item in r:
print(item, test[item]) # 0 q,1 w,2 e

方法2:

test = input('>>>')
for item in range(0, len(test)):
    print(item, test[item])

##################### 1个深灰魔法 ######################
字符串一旦创建,不可修改
一旦修改或者拼接,都会造成重新生成字符串
name = "william"
age = "22"

info = name + age
print(info)

  

方法三、getconf GNU_LIBC_VERSION

列表(list)

如:[“william”,’zhurui’]、[“ray”,”william”]

发表评论

电子邮件地址不会被公开。 必填项已用*标注

标签:
网站地图xml地图