A wireless ad hoc network is an autonomous system that is made up of collaborative mobile nodes. Wireless ad hoc networks can be dynamically set up without relying on any pre-existing infrastructure or central administration. Implementing public key management is a challenging issue in wireless ad hoc networks due to its salient nature of the network. Without an online third party, the public key certificate distribution is vulnerable to man-in-the-middle attacks. In this paper, we present On-demand Public Key Management (OPKM), a novel public key management scheme for wireless ad hoc networks. OPKM makes use of broadcasting technology and digital signature mechanism to provide key management service on demand, while protecting the certificate distribution against man-in-the-middle attacks. OPKM can be fully organised by nodes themselves without the need of any online trust third party.