1package com.android.hotspot2.osu.commands;
2
3import android.util.Base64;
4
5import com.android.hotspot2.omadm.OMAException;
6import com.android.hotspot2.omadm.XMLNode;
7
8import java.nio.charset.StandardCharsets;
9import java.util.HashMap;
10import java.util.Map;
11
12/*
13    <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
14        <env:Header/>
15        <env:Body>
16            <spp:sppPostDevDataResponse xmlns:spp="http://www.wi-fi.org/specifications/hotspot2dot0/v1.0/spp"
17                                        spp:sessionID="A40103ACEDE94C45BA127A41239BD60F" spp:sppStatus="OK"
18                                        spp:sppVersion="1.0">
19                <spp:exec>
20                    <spp:getCertificate enrollmentProtocol="EST">
21                        <spp:enrollmentServerURI>https://osu-server.r2-testbed-rks.wi-fi.org:9446/.well-known/est
22                        </spp:enrollmentServerURI>
23                        <spp:estUserID>a88c4830-aafd-420b-b790-c08f457a0fa3</spp:estUserID>
24                        <spp:estPassword>cnVja3VzMTIzNA==</spp:estPassword>
25                    </spp:getCertificate>
26                </spp:exec>
27            </spp:sppPostDevDataResponse>
28        </env:Body>
29    </env:Envelope>
30 */
31
32public class GetCertData implements OSUCommandData {
33    private final String mProtocol;
34    private final String mServer;
35    private final String mUserName;
36    private final byte[] mPassword;
37
38    public GetCertData(XMLNode commandNode) throws OMAException {
39        mProtocol = commandNode.getAttributeValue("enrollmentProtocol");
40
41        Map<String, String> values = new HashMap<>(3);
42        for (XMLNode node : commandNode.getChildren()) {
43            values.put(node.getStrippedTag(), node.getText());
44        }
45
46        mServer = values.get("enrollmentserveruri");
47        mUserName = values.get("estuserid");
48        mPassword = Base64.decode(values.get("estpassword"), Base64.DEFAULT);
49    }
50
51    public String getProtocol() {
52        return mProtocol;
53    }
54
55    public String getServer() {
56        return mServer;
57    }
58
59    public String getUserName() {
60        return mUserName;
61    }
62
63    public byte[] getPassword() {
64        return mPassword;
65    }
66
67    @Override
68    public String toString() {
69        return "GetCertData " +
70                "protocol='" + mProtocol + '\'' +
71                ", server='" + mServer + '\'' +
72                ", userName='" + mUserName + '\'' +
73                ", password='" + new String(mPassword, StandardCharsets.ISO_8859_1) + '\'';
74    }
75}
76