-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Posture Checks for JVM/Android (#97)
* add controller API dealing with posture checks * Implement PostureCheckService * implement Android Posture service * submit posture data * handle security posture failures
- Loading branch information
Showing
12 changed files
with
426 additions
and
30 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
ziti-android/src/androidTest/java/org/openziti/android/PostureProviderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2018-2020 NetFoundry, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.openziti.android | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.openziti.api.PostureQuery | ||
import org.openziti.api.PostureQueryType | ||
import org.openziti.api.PostureResponse | ||
import org.openziti.posture.PostureService | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class PostureProviderTest { | ||
|
||
lateinit var postureService: PostureService | ||
@Before | ||
fun setup() { | ||
postureService = PostureService() | ||
} | ||
@Test | ||
fun osPostureTest() { | ||
postureService.registerServiceCheck("servid", PostureQuery(PostureQueryType.OS, "checkid", false, null)) | ||
|
||
val pr = postureService.getPosture()[0] | ||
assertEquals(PostureQueryType.OS, pr.typeId) | ||
val os = pr.data as PostureResponse.OS | ||
assertEquals("android", os.type) | ||
val verComp = os.version.split(".") | ||
assertEquals(3, verComp.size) | ||
} | ||
|
||
@Test | ||
fun macPostureTest() { | ||
postureService.registerServiceCheck("servid", PostureQuery(PostureQueryType.MAC, "checkid", false, null)) | ||
|
||
val pr = postureService.getPosture()[0] | ||
assertEquals(PostureQueryType.MAC, pr.typeId) | ||
val mac = pr.data as PostureResponse.MAC | ||
assert(mac.macAddresses.isNotEmpty()) | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
ziti-android/src/main/java/org/openziti/android/PostureProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2018-2020 NetFoundry, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.openziti.android | ||
|
||
import android.os.Build | ||
import org.openziti.api.PostureQuery | ||
import org.openziti.api.PostureQueryType | ||
import org.openziti.api.PostureResponse | ||
import org.openziti.posture.PostureService | ||
import org.openziti.posture.PostureServiceProvider | ||
import java.net.NetworkInterface | ||
|
||
class PostureProvider: PostureServiceProvider { | ||
override fun getPostureService(): PostureService = AndroidPostureService | ||
|
||
object AndroidPostureService: PostureService { | ||
val androidVersion: String by lazy { | ||
Build.VERSION.RELEASE.split(".").plus(arrayOf("0","0")).take(3).joinToString(".") | ||
} | ||
val androidBuild: String by lazy { | ||
Build.VERSION.SECURITY_PATCH.replace("-", "") // turn date into an int | ||
} | ||
|
||
val macAddresses: Array<String> by lazy { | ||
NetworkInterface.getNetworkInterfaces().toList() | ||
.map { it.hardwareAddress } | ||
.filterNotNull() | ||
.map { it.joinToString(":"){ b -> "%02x".format(b) } } | ||
.toTypedArray() | ||
} | ||
|
||
val queries = mutableMapOf<String, PostureQuery>() | ||
|
||
override fun registerServiceCheck(serviceId: String, query: PostureQuery) { | ||
queries.put(query.id, query) | ||
} | ||
|
||
override fun getPosture(): Array<PostureResponse> = queries.values | ||
.map{ processQuery(it) } | ||
.filterNotNull().toTypedArray() | ||
|
||
internal fun processQuery(q: PostureQuery): PostureResponse? = when(q.queryType) { | ||
PostureQueryType.OS -> PostureResponse.OS(q.id, "android", androidVersion, androidBuild) | ||
PostureQueryType.MAC -> PostureResponse.MAC(q.id, macAddresses) | ||
else -> null | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...-android/src/main/resources/META-INF/services/org.openziti.posture.PostureServiceProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# Copyright (c) 2018-2020 NetFoundry, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# | ||
# Copyright (c) 2018-2020 NetFoundry, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
|
||
org.openziti.android.PostureProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.